{"id":390395,"date":"2024-12-11T09:51:50","date_gmt":"2024-12-11T09:51:50","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=390395"},"modified":"2024-12-11T09:51:50","modified_gmt":"2024-12-11T09:51:50","slug":"exclusions-antivirus-linux","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/exclusions-antivirus-linux\/","title":{"rendered":"Guide IT\u00a0: personnalisation des exclusions antivirus \u00e0 l&rsquo;aide d&rsquo;un script Bash sous Linux\u00a0"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Pour les professionnels de l&rsquo;informatique et les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a>, il est essentiel de conserver des informations pr\u00e9cises sur l&rsquo;\u00e9tat de l&rsquo;antivirus sur les appareils. Le suivi des versions, des \u00e9tats et des statuts de mise \u00e0 jour des antivirus garantit l&rsquo;application des politiques de s\u00e9curit\u00e9 et la protection des syst\u00e8mes. Pour les environnements Linux, l&rsquo;automatisation peut simplifier ce processus. Cet article examine un script Bash con\u00e7u pour g\u00e9rer les exclusions antivirus sur les p\u00e9riph\u00e9riques, offrant aux \u00e9quipes informatiques un outil pratique pour maintenir leurs informations de s\u00e9curit\u00e9 sur les terminaux.<\/p>\n<h2>Contexte<\/h2>\n<p>Dans les environnements informatiques, en particulier pour les entreprises MSP qui g\u00e8rent divers parcs d&rsquo;appareils, le statut de l&rsquo;antivirus est un indicateur cl\u00e9. Cependant, des divergences apparaissent souvent entre l&rsquo;\u00e9tat r\u00e9el du logiciel antivirus sur un appareil et la fa\u00e7on dont il appara\u00eet dans les outils de contr\u00f4le. Ce script permet aux professionnels de l&rsquo;informatique de d\u00e9finir ou de mettre \u00e0 jour manuellement les informations relatives \u00e0 l&rsquo;antivirus, notamment son nom, sa version, son \u00e9tat et son statut de mise \u00e0 jour. En permettant la personnalisation ou la suppression des exclusions, il rationalise la gestion de la s\u00e9curit\u00e9 des terminaux dans les environnements qui s&rsquo;appuient sur des outils tels que NinjaOne.<\/p>\n<h2>Le script\u00a0:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/usr\/bin\/env bash\r\n#\r\n# Description: Add an antivirus to the device details or override the existing antivirus information.\r\n# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n# Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#\r\n# Preset Parameter: --antivirusName \"ReplaceMeWithYourDesiredName\"\r\n#   Name of the antivirus you would like to appear in the device details.\r\n#\r\n# Preset Parameter: --antivirusVersion \"1.0.2\"\r\n#   Specify the version number of the antivirus.\r\n#\r\n# Preset Parameter: --antivirusStatus \"Up-to-Date\"\r\n#   Specify whether the antivirus definitions are Up-to-Date, Out-of-Date, or Unknown.\r\n#\r\n# Preset Parameter: --antivirusState \"ON\"\r\n#   Specify the current status of the antivirus.\r\n#\r\n# Preset Parameter: --removeOverride\r\n#   Remove all existing overrides.\r\n#\r\n# Preset Parameter: --antivirusState\r\n#   Append or update an existing override.\r\n#\r\n# Preset Parameter: --help\r\n#\t\tDisplays a help menu.\r\n#\r\n# Release Notes: Initial Release\r\n\r\n# Initialize variables\r\n_arg_antivirusName=\r\n_arg_antivirusVersion=\r\n_arg_antivirusStatus=\r\n_arg_antivirusState=\r\n_arg_removeOverride=\"off\"\r\n_arg_append=\"off\"\r\n\r\n# Function to display help message\r\nprint_help() {\r\n  printf '\\n\\n%s\\n\\n' 'Usage: [--antivirusName|-n &lt;arg&gt;] [--antivirusVersion|-v &lt;arg&gt;] [--antivirusStatus|--status &lt;arg&gt;] [--antivirusState|--state &lt;arg&gt;] [--removeOverride|-r] [--append|-a] [--help|-h] '\r\n  printf '%s\\n' 'Preset Parameter: --antivirusName \"ReplaceMeWithYourDesiredName\"'\r\n  printf '\\t%s\\n' \"Name of the antivirus you would like to appear in the device details.\"\r\n  printf '%s\\n' 'Preset Parameter: --antivirusVersion \"1.0.2\"'\r\n  printf '\\t%s\\n' \"Specify the version number of the antivirus.\"\r\n  printf '%s\\n' 'Preset Parameter: --antivirusStatus \"Up-to-Date\"'\r\n  printf '\\t%s\\n' \"Specify whether the antivirus definitions are Up-to-Date, Out-of-Date, or Unknown.\"\r\n  printf '%s\\n' 'Preset Parameter: --antivirusState \"ON\"'\r\n  printf '\\t%s\\n' \"Specify the current status of the antivirus.\"\r\n  printf '%s\\n' 'Preset Parameter: --removeOverride'\r\n  printf '\\t%s\\n' \"Remove all existing overrides.\"\r\n  printf '%s\\n' 'Preset Parameter: --antivirusState'\r\n  printf '\\t%s\\n' \"Append or update an existing override.\"\r\n  printf '\\n%s\\n' 'Preset Parameter: --help'\r\n  printf '\\t%s\\n' \"Displays this help menu.\"\r\n}\r\n\r\n# Function to print an error message and exit\r\ndie() {\r\n  local _ret=\"${2:-1}\"\r\n  echo \"$1\" &gt;&amp;2\r\n  test \"${_PRINT_HELP:-no}\" = yes &amp;&amp; print_help &gt;&amp;2\r\n  exit \"${_ret}\"\r\n}\r\n\r\n# Function to parse command line arguments\r\nparse_commandline() {\r\n  while test $# -gt 0; do\r\n    _key=\"$1\"\r\n    case \"$_key\" in\r\n    --antivirusName | --antivirusname | --name | -n)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the argument '$_key'.\" 1\r\n      _arg_antivirusName=$2\r\n      shift\r\n      ;;\r\n    --antivirusName=*)\r\n      _arg_antivirusName=\"${_key##--antivirusName=}\"\r\n      ;;\r\n    --antivirusVersion | --antivirusversion | --version | -v)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the argument '$_key'.\" 1\r\n      _arg_antivirusVersion=$2\r\n      shift\r\n      ;;\r\n    --antivirusVersion=*)\r\n      _arg_antivirusVersion=\"${_key##--antivirusVersion=}\"\r\n      ;;\r\n    --antivirusStatus | --antivirusstatus | --status)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the argument '$_key'.\" 1\r\n      _arg_antivirusStatus=$2\r\n      shift\r\n      ;;\r\n    --antivirusStatus=*)\r\n      _arg_antivirusStatus=\"${_key##--antivirusStatus=}\"\r\n      ;;\r\n    --antivirusState | --antivirusstate | --state)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the argument '$_key'.\" 1\r\n      _arg_antivirusState=$2\r\n      shift\r\n      ;;\r\n    --antivirusState=*)\r\n      _arg_antivirusState=\"${_key##--antivirusState=}\"\r\n      ;;\r\n    --removeOverride | --remove | -r)\r\n      _arg_removeOverride=\"on\"\r\n      ;;\r\n    --append | --Append | -a)\r\n      _arg_append=\"on\"\r\n      ;;\r\n    --help | -h)\r\n      _PRINT_HELP=yes die 0\r\n      ;;\r\n    *)\r\n      _PRINT_HELP=yes die \"[Error] Got an unexpected argument '$1'\" 1\r\n      ;;\r\n    esac\r\n    shift\r\n  done\r\n}\r\n\r\n# Parse the command line arguments\r\nparse_commandline \"$@\"\r\n\r\n# Replace commandline parameters with script form variables\r\nif [[ -n $avName ]]; then\r\n  _arg_antivirusName=\"$avName\"\r\nfi\r\nif [[ -n $avVersion ]]; then\r\n  _arg_antivirusVersion=\"$avVersion\"\r\nfi\r\nif [[ -n $avStatus ]]; then\r\n  _arg_antivirusStatus=\"$avStatus\"\r\nfi\r\nif [[ -n $avState ]]; then\r\n  _arg_antivirusState=\"$avState\"\r\nfi\r\nif [[ -n $append &amp;&amp; $append == \"true\" ]]; then\r\n  _arg_append=\"on\"\r\nfi\r\nif [[ -n $removeOverride &amp;&amp; $removeOverride == \"true\" ]]; then\r\n  _arg_removeOverride=\"on\"\r\nfi\r\n\r\n# Ensure that removing an override and adding\/updating an override are not done simultaneously\r\nif [[ $_arg_removeOverride == \"on\" &amp;&amp; (-n $_arg_antivirusName || -n $_arg_antivirusState || -n $_arg_antivirusStatus || -n $_arg_antivirusVersion || $_arg_append == \"on\") ]]; then\r\n  _PRINT_HELP=no die \"[Error] Cannot remove an override and add an override at the same time.\" 1\r\nfi\r\n\r\n# Check for required antivirus name and escape special characters if necessary\r\nreservedCharacters='[\\\"]'\r\nif [[ -z $_arg_antivirusName &amp;&amp; $_arg_removeOverride != \"on\" ]]; then\r\n  if [[ $_arg_append == \"on\" ]]; then\r\n    _PRINT_HELP=yes die \"[Error] Antivirus name was not given. The antivirus name is required when updating or adding a new override!\" 1\r\n  else\r\n    _PRINT_HELP=yes die \"[Error] Antivirus name was not given. Antivirus name, state, and status are required when adding a new override!\" 1\r\n  fi\r\nelif [[ -n $_arg_antivirusName &amp;&amp; $_arg_antivirusName =~ $reservedCharacters ]]; then\r\n  _arg_antivirusName=${_arg_antivirusName\/\/\\\\\/\\\\\\\\}\r\n  _arg_antivirusName=${_arg_antivirusName\/\/\\\"\/\\\\\\\"}\r\nfi\r\n\r\n# Check for required antivirus status\r\nif [[ -z $_arg_antivirusStatus &amp;&amp; $_arg_removeOverride != \"on\" &amp;&amp; $_arg_append != \"on\" ]]; then\r\n  _PRINT_HELP=yes die \"[Error] Antivirus status was not given. Antivirus name, state, and status are required!\" 1\r\nfi\r\n\r\n# Validate antivirus status\r\nif [[ -n $_arg_antivirusStatus &amp;&amp; $_arg_antivirusStatus != \"Up-to-Date\" &amp;&amp; $_arg_antivirusStatus != \"Out-of-Date\" &amp;&amp; $_arg_antivirusStatus != \"Unknown\" ]]; then\r\n  _PRINT_HELP=no die \"[Error] An invalid antivirus status of '$_arg_antivirusStatus' was given. Only the following statuses are valid. 'Up-to-Date', 'Out-of-Date', and 'Unknown'.\" 1\r\nfi\r\n\r\n# Check for required antivirus state\r\nif [[ -z $_arg_antivirusState &amp;&amp; $_arg_removeOverride != \"on\" &amp;&amp; $_arg_append != \"on\" ]]; then\r\n  _PRINT_HELP=yes die \"[Error] Antivirus state was not given. Antivirus name, state, and status are required!\" 1\r\nelse\r\n  _arg_antivirusState=$(echo \"$_arg_antivirusState\" | tr '[:lower:]' '[:upper:]')\r\nfi\r\n\r\n# Validate antivirus state\r\nif [[ -n $_arg_antivirusState &amp;&amp; $_arg_antivirusState != \"ON\" &amp;&amp; $_arg_antivirusState != \"OFF\" &amp;&amp; $_arg_antivirusState != \"EXPIRED\" &amp;&amp; $_arg_antivirusState != \"SNOOZED\" &amp;&amp; $_arg_antivirusState != \"UNKNOWN\" ]]; then\r\n  _PRINT_HELP=no die \"[Error] An invalid antivirus state of '$_arg_antivirusState' was given. Only the following states are valid. 'ON', 'OFF', 'EXPIRED', 'SNOOZED', and 'UNKNOWN'.\" 1\r\nfi\r\n\r\n# Validate antivirus version\r\nif [[ -n $_arg_antivirusVersion &amp;&amp; $_arg_antivirusVersion =~ [^0-9\\.] ]]; then\r\n  _PRINT_HELP=no die \"[Error] The antivirus version given '$_arg_antivirusVersion' contains an invalid character. Only the following characters are allowed. '0-9' and '.'\" 1\r\nfi\r\n\r\n# Check if the removeOverride flag is set to \"on\"\r\nif [[ $_arg_removeOverride == \"on\" ]]; then\r\n  echo \"Removing override as requested.\"\r\n  # Check if the override file exists\r\n  if [[ ! -f \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" ]]; then\r\n    echo \"No override present.\"\r\n    exit 0\r\n  # Try to remove the override file and capture any error output\r\n  elif output=$(rm \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" 2&gt;&amp;1); then\r\n    echo \"Succesfully removed override!\"\r\n    exit 0\r\n  # Print an error message if the removal fails\r\n  else\r\n    echo \"[Error] Failed to remove override!\"\r\n    echo \"[Error] $output\"\r\n  fi\r\nfi\r\n\r\n# Check if the customization directory exists\r\nif [[ ! -d \"\/opt\/NinjaRMMAgent\/programdata\/customization\" ]]; then\r\n  echo \"Creating customization folder at '\/opt\/NinjaRMMAgent\/programdata\/customization'.\"\r\n  # Try to create the customization directory and capture any error output\r\n  if output=$(mkdir \"\/opt\/NinjaRMMAgent\/programdata\/customization\" 2&gt;&amp;1); then\r\n    echo \"Folder created.\"\r\n  else\r\n    # Print an error message if the creation fails\r\n    echo \"[Error] Unable to create customization folder.\" &gt;&amp;2\r\n    echo \"[Error] $output\" &gt;&amp;2\r\n    exit 1\r\n  fi\r\nfi\r\n\r\n# Check if the append flag is set to \"on\" and the override JSON file exists\r\nif [[ $_arg_append == \"on\" &amp;&amp; -f \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" ]]; then\r\n  # Extract antivirus names, versions, statuses and states from the JSON file\r\n  avNames=$(grep \"av_name\" \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" | tr -s \" \" | sed s\/\\\"av_name\\\":\/\/g | sed -e 's\/^[[:space:]]*\/\/' | sed 's\/[\\\",]\/\/g' | sed -e 's\/[[:space:]]*$\/\/')\r\n  avVersions=$(grep \"av_version\" \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" | tr -s \" \" | sed s\/\\\"av_version\\\":\/\/g | sed -e 's\/^[[:space:]]*\/\/' | sed 's\/[\\\",]\/\/g' | sed -e 's\/[[:space:]]*$\/\/')\r\n  avStatuses=$(grep \"av_status\" \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" | tr -s \" \" | sed s\/\\\"av_status\\\":\/\/g | sed -e 's\/^[[:space:]]*\/\/' | sed 's\/[\\\",]\/\/g' | sed -e 's\/[[:space:]]*$\/\/')\r\n  avStates=$(grep \"av_state\" \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\" | tr -s \" \" | sed s\/\\\"av_state\\\":\/\/g | sed -e 's\/^[[:space:]]*\/\/' | sed 's\/[\\\",]\/\/g' | sed -e 's\/[[:space:]]*$\/\/')\r\n\r\n  # Find the line number of the existing antivirus entry with the given name\r\n  existingAV=$(echo \"$avNames\" | grep -n \"$_arg_antivirusName\" | sed 's\/:.*\/\/g')\r\n\r\n  # Determine the desired antivirus status\r\n  if [[ -n $_arg_antivirusStatus ]]; then\r\n    desiredStatus=$_arg_antivirusStatus\r\n  elif [[ -n $existingAV ]]; then\r\n    desiredStatus=$(echo \"$avStatuses\" | sed -n \"${existingAV}p\")\r\n  fi\r\n\r\n  # Determine the desired antivirus state\r\n  if [[ -n $_arg_antivirusState ]]; then\r\n    desiredState=$_arg_antivirusState\r\n  elif [[ -n $existingAV ]]; then\r\n    desiredState=$(echo \"$avStates\" | sed -n \"${existingAV}p\")\r\n  fi\r\n\r\n  # Check if both status and state are provided\r\n  if [[ -z $desiredStatus || -z $desiredState ]]; then\r\n    _PRINT_HELP=no die \"[Error] Antivirus state or status are missing from the override entry. Please provide both in addition to the antivirus name!\" 1\r\n  fi\r\n\r\n  # Update the existing antivirus entry if found\r\n  if [[ -n $existingAV ]]; then\r\n    echo \"Attempting to update override.\"\r\n\r\n    # Update antivirus version if provided\r\n    if [[ -n $_arg_antivirusVersion ]]; then\r\n      modified_json=$(awk -v target=\"$existingAV\" -v value=\"$_arg_antivirusVersion\" 'BEGIN { av_count = 1 }\r\n      \/av_version\/ { \r\n        if (av_count == target){ \r\n          sub( \/av_version.*\/ , \"av_version\\\":  \\\"\"value\"\\\",\" ) \r\n        }\r\n        av_count++\r\n      }{ print }' \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\")\r\n\r\n      if echo \"$modified_json\" &gt;\"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\"; then\r\n        echo \"Successfully updated the antivirus version!\"\r\n      else\r\n        echo \"[Error] Failed to update the antivirus version!\" &gt;&amp;2\r\n        exit 1\r\n      fi\r\n    fi\r\n\r\n    # Update antivirus status if provided\r\n    if [[ -n $_arg_antivirusStatus ]]; then\r\n      modified_json=$(awk -v target=\"$existingAV\" -v value=\"$_arg_antivirusStatus\" 'BEGIN { av_count = 1 }\r\n      \/av_status\/ { \r\n        if (av_count == target){ \r\n          sub( \/av_status.*\/ , \"av_status\\\":  \\\"\"value\"\\\",\" ) \r\n        }\r\n        av_count++\r\n      }{print}' \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\")\r\n\r\n      if echo \"$modified_json\" &gt;\"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\"; then\r\n        echo \"Successfully updated the override status!\"\r\n      else\r\n        echo \"[Error] Failed to update the override status!\" &gt;&amp;2\r\n        exit 1\r\n      fi\r\n    fi\r\n\r\n    # Update antivirus state if provided\r\n    if [[ -n $_arg_antivirusState ]]; then\r\n      modified_json=$(awk -v target=\"$existingAV\" -v value=\"$_arg_antivirusState\" 'BEGIN { av_count = 1 }\r\n      \/av_state\/ { \r\n        if (av_count == target){ \r\n          sub( \/av_state.*\/ , \"av_state\\\":  \\\"\"value\"\\\"\" ) \r\n        }\r\n        av_count++\r\n      }{print}' \"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\")\r\n\r\n      if echo \"$modified_json\" &gt;\"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\"; then\r\n        echo \"Successfully updated the override state!\"\r\n      else\r\n        echo \"[Error] Failed to update the override state!\" &gt;&amp;2\r\n        exit 1\r\n      fi\r\n    fi\r\n\r\n    exit\r\n  fi\r\n\r\n  # Print a message indicating that the script is attempting to append an override\r\n  echo \"Attempting to append override.\"\r\n  # Initialize a counter for indexing\r\n  i=1\r\n  # Initialize the JSON structure for antivirus overrides\r\n  avOverrides=\"{\r\n  \\\"av_override\\\": [\r\n\"\r\n  # Loop through each antivirus name\r\n  for avName in $avNames; do\r\n    # Extract the corresponding antivirus version, status and state for the current index\r\n    avVersion=$(echo \"$avVersions\" | sed -n \"${i}p\")\r\n    avStatus=$(echo \"$avStatuses\" | sed -n \"${i}p\")\r\n    avState=$(echo \"$avStates\" | sed -n \"${i}p\")\r\n\r\n    # Append the current antivirus entry to the JSON structure\r\n    avOverrides+=\"    {\r\n      \\\"av_name\\\":  \\\"${avName}\\\",\r\n      \\\"av_version\\\": \\\"${avVersion}\\\",\r\n      \\\"av_status\\\":  \\\"${avStatus}\\\",\r\n      \\\"av_state\\\": \\\"${avState}\\\"\r\n    },\r\n\"\r\n    # Increment the counter for the next iteration\r\n    i=$((i + 1))\r\n  done\r\n\r\n  # Close the JSON structure\r\n  avOverrides+=\"    {\r\n      \\\"av_name\\\":  \\\"${_arg_antivirusName}\\\",\r\n      \\\"av_version\\\": \\\"${_arg_antivirusVersion}\\\",\r\n      \\\"av_status\\\":  \\\"${_arg_antivirusStatus}\\\",\r\n      \\\"av_state\\\": \\\"${_arg_antivirusState}\\\"\r\n    }\r\n  ]\r\n}\r\n\"\r\n\r\n  # Attempt to write the JSON structure containing antivirus overrides to the specified file\r\n  if echo \"$avOverrides\" &gt;\"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\"; then\r\n    echo \"Succesfully added override.\"\r\n    exit\r\n  else\r\n    echo \"[Error] Failed to add override.\" &gt;&amp;2\r\n    exit 1\r\n  fi\r\nfi\r\n\r\n# Check if the antivirus state or status arguments are missing\r\nif [[ -z $_arg_antivirusState || -z $_arg_antivirusStatus ]]; then\r\n  _PRINT_HELP=no die \"[Error] Antivirus name, state and status are required when adding a new override!\" 1\r\nfi\r\n\r\n# Construct the JSON string for the antivirus override\r\nJSON_STRING=\"{\r\n  \\\"av_override\\\": [\r\n    {\r\n      \\\"av_name\\\":  \\\"${_arg_antivirusName}\\\",\r\n      \\\"av_version\\\":  \\\"${_arg_antivirusVersion}\\\",\r\n      \\\"av_status\\\":  \\\"${_arg_antivirusStatus}\\\",\r\n      \\\"av_state\\\":  \\\"${_arg_antivirusState}\\\"\r\n    }\r\n  ]\r\n}\r\n\"\r\n\r\n# Attempt to write the JSON string to the specified file\r\nif echo \"$JSON_STRING\" &gt;\"\/opt\/NinjaRMMAgent\/programdata\/customization\/av_override.json\"; then\r\n  # If the write operation is successful, print a success message\r\n  echo \"Succesfully created override.\"\r\nelse\r\n  # If the write operation fails, print an error message to standard error\r\n  echo \"[Error] Failed to create override.\" &gt;&amp;2\r\n  exit 1\r\nfi\r\n<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Gagnez du temps gr\u00e2ce \u00e0 plus de 300 scripts du Dojo NinjaOne.<\/p>\n<p>\u2192 <a class=\"waffle-rich-text-link\" href=\"https:\/\/www.ninjaone.com\/fr\/phase-de-test-gratuit\/\">Obtenir l&rsquo;acc\u00e8s<\/a><\/p>\n<\/div>\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Ce script automatise l&rsquo;ajout ou la mise \u00e0 jour des exclusions antivirus dans un fichier de configuration bas\u00e9 sur JSON. Voici comment cela fonctionne, \u00e9tape par \u00e9tape\u00a0:<\/p>\n<p><strong>1. Initialisation des param\u00e8tres<\/strong><\/p>\n<p>a. Le script commence par d\u00e9finir des variables pour le nom, la version, le statut et l&rsquo;\u00e9tat de l&rsquo;antivirus. Des marqueurs comme &#8211;removeOverride et &#8211;append sont \u00e9galement initialis\u00e9s pour g\u00e9rer des actions sp\u00e9cifiques.<\/p>\n<p><strong>2. Analyse de la ligne de commande<\/strong><\/p>\n<p>a. La fonction parse_commandline traite les arguments fournis lors de l&rsquo;ex\u00e9cution du script. Par exemple, &#8211;antivirusName \u00ab\u00a0MyAntivirus\u00a0\u00bb d\u00e9finit le nom de l&rsquo;antivirus.<\/p>\n<p><strong>3. Validation<\/strong><\/p>\n<p>a. Le script s&rsquo;assure que les param\u00e8tres obligatoires sont fournis lorsqu&rsquo;ils sont requis. Il v\u00e9rifie la validit\u00e9 des statuts (\u00e0 jour, obsol\u00e8te ou inconnu) et des \u00e9tats (activ\u00e9, d\u00e9sactiv\u00e9, expir\u00e9, remise \u00e0 plus tard ou inconnu).<\/p>\n<p><strong>4. Suppression des exclusions<\/strong><\/p>\n<p>a. Si l&rsquo;option &#8211;removeOverride est activ\u00e9e, le script supprime le fichier JSON existant. Si aucun fichier de ce type n&rsquo;existe, il se termine de mani\u00e8re \u00e9l\u00e9gante.<\/p>\n<p><strong>5. Ajout ou mise \u00e0 jour des exclusions<\/strong><\/p>\n<p>a. Lorsque l&rsquo;option &#8211;append est utilis\u00e9e, le script v\u00e9rifie les entr\u00e9es existantes dans le fichier JSON. Il met \u00e0 jour les d\u00e9tails d&rsquo;une entr\u00e9e antivirus existante ou en ajoute une nouvelle.<\/p>\n<p><strong>6. R\u00e9daction des exclusions<\/strong><\/p>\n<p>a. Si l&rsquo;option &#8211;append n&rsquo;est pas activ\u00e9e, le script \u00e9crit une nouvelle structure JSON avec les d\u00e9tails de l&rsquo;antivirus sp\u00e9cifi\u00e9. Cette structure est sauvegard\u00e9e \u00e0 un emplacement d\u00e9sign\u00e9.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<h3>Sc\u00e9nario : une entreprise MSP qui g\u00e8re les appareils de ses clients<\/h3>\n<p>Imaginez qu&rsquo;un fournisseur de services de gestion surveille les appareils de plusieurs clients. Une nouvelle mise \u00e0 jour de l&rsquo;antivirus entra\u00eene des retards dans la synchronisation de l&rsquo;\u00e9tat avec leur outil de surveillance. En d\u00e9ployant ce script sur les appareils concern\u00e9s, le MSP peut temporairement remplacer le statut, en marquant l&rsquo;antivirus comme \u00ab\u00a0Up-to-Date\u00a0\u00bb (\u00e0 jour) et \u00ab\u00a0ON\u00a0\u00bb (activ\u00e9), ce qui garantit que les rapports de conformit\u00e9 restent exacts jusqu&rsquo;\u00e0 ce que le probl\u00e8me soit r\u00e9solu.<\/p>\n<h2>Comparaisons<\/h2>\n<p>D&rsquo;autres m\u00e9thodes de gestion de l&rsquo;\u00e9tat de l&rsquo;antivirus consistent \u00e0 modifier manuellement le fichier JSON ou \u00e0 s&rsquo;appuyer sur les outils int\u00e9gr\u00e9s aux plateformes de surveillance et de gestion \u00e0 distance (RMM). Par rapport aux \u00e9ditions manuelles, ce script r\u00e9duit les erreurs humaines et acc\u00e9l\u00e8re le processus. Contrairement aux outils sp\u00e9cifiques \u00e0 une plateforme, il offre une certaine souplesse pour les environnements Linux o\u00f9 de telles int\u00e9grations n&rsquo;existent pas forc\u00e9ment.<\/p>\n<h2>FAQ<\/h2>\n<ul>\n<li><strong>Ce script peut-il fonctionner avec tous les logiciels antivirus\u00a0?<\/strong><br \/>\nIl n&rsquo;interagit pas directement avec le logiciel antivirus, mais modifie le fichier JSON contenant les exclusions, ce qui le rend ind\u00e9pendant des solutions antivirus sp\u00e9cifiques.<\/li>\n<li><strong>Que se passe-t-il si je l&rsquo;ex\u00e9cute sans les arguments requis\u00a0?<\/strong><br \/>\nLe script affiche des messages d&rsquo;erreur d\u00e9taill\u00e9s et des instructions d&rsquo;utilisation pour guider vers une ex\u00e9cution correcte.<\/li>\n<li><strong>Comment annuler les modifications apport\u00e9es par ce script\u00a0?<\/strong><br \/>\nUtilisez l&rsquo;option &#8211;removeOverride pour supprimer le fichier de configuration.<\/li>\n<li><strong>Puis-je utiliser ce script sur des syst\u00e8mes autres que Linux\u00a0?<\/strong><br \/>\nIl est con\u00e7u pour les environnements Linux car il s&rsquo;appuie sur Bash et les chemins de fichiers Linux.<\/li>\n<\/ul>\n<h2>Implications<\/h2>\n<p>L&rsquo;utilisation efficace de ce script garantit une repr\u00e9sentation pr\u00e9cise de l&rsquo;\u00e9tat des antivirus sur l&rsquo;ensemble des appareils. Cela permet de r\u00e9duire les fausses alertes dans la surveillance de la s\u00e9curit\u00e9, ce qui renforce la cybers\u00e9curit\u00e9 de l&rsquo;entreprise. Toutefois, une utilisation incorrecte ou des exclusions non valides peuvent entra\u00eener des divergences, ce qui souligne la n\u00e9cessit\u00e9 d&rsquo;une gestion prudente.<\/p>\n<h2>Recommandations<\/h2>\n<ul>\n<li>Testez toujours le script sur un appareil qui n&rsquo;est pas dans un environnement de production afin de v\u00e9rifier son comportement.<\/li>\n<li>Utilisez des conventions de d\u00e9nomination claires et coh\u00e9rentes pour les solutions antivirus afin d&rsquo;\u00e9viter les conflits.<\/li>\n<li>Documentez les exclusions appliqu\u00e9es aux appareils pour r\u00e9f\u00e9rence ult\u00e9rieure.<\/li>\n<li>Limitez l&rsquo;acc\u00e8s \u00e0 ce script afin d&rsquo;\u00e9viter toute modification non autoris\u00e9e.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Ce script illustre la mani\u00e8re dont l&rsquo;automatisation am\u00e9liore l&rsquo;<a href=\"https:\/\/www.ninjaone.com\/fr\/efficacite\">efficacit\u00e9<\/a> et la pr\u00e9cision de la gestion informatique. Pour les utilisateurs de NinjaOne ou de plateformes RMM similaires, l&rsquo;utilisation d&rsquo;outils tels que ce script avec des fonctions avanc\u00e9es de gestion des terminaux garantit une posture de s\u00e9curit\u00e9 solide. NinjaOne simplifie la visibilit\u00e9 et la gestion des terminaux, en fournissant une plateforme unifi\u00e9e pour rationaliser les op\u00e9rations informatiques tout en relevant des d\u00e9fis tels que les exclusions antivirus avec pr\u00e9cision.<\/p>\n","protected":false},"author":35,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4211],"use_cases":[4284],"class_list":["post-390395","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/390395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/comments?post=390395"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=390395"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=390395"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=390395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}