{"id":353648,"date":"2024-08-27T09:15:21","date_gmt":"2024-08-27T09:15:21","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/verification-de-l-existence-de-fichiers-macos\/"},"modified":"2024-10-13T19:07:40","modified_gmt":"2024-10-13T19:07:40","slug":"verification-de-l-existence-de-fichiers-macos","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/verification-de-l-existence-de-fichiers-macos\/","title":{"rendered":"Comment v\u00e9rifier l&rsquo;existence de fichiers et de dossiers de fa\u00e7on automatis\u00e9e dans macOS ?"},"content":{"rendered":"<p>Dans le monde informatique, l&rsquo;automatisation des t\u00e2ches r\u00e9p\u00e9titives permet de gagner du temps et de r\u00e9duire les erreurs. L&rsquo;une de ces t\u00e2ches consiste \u00e0 v\u00e9rifier l&rsquo;existence de fichiers ou de dossiers sp\u00e9cifiques dans plusieurs r\u00e9pertoires. Qu&rsquo;il s&rsquo;agisse de conformit\u00e9, de surveillance du syst\u00e8me ou de d\u00e9pannage, disposer <strong>d&rsquo;un moyen automatis\u00e9 de v\u00e9rifier la pr\u00e9sence de fichiers<\/strong> peut s&rsquo;av\u00e9rer inestimable pour les professionnels de l&rsquo;informatique et les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\" target=\"_blank\" rel=\"noopener\">fournisseurs de services g\u00e9r\u00e9s (MSP).<\/a> Cet article pr\u00e9sente un script Bash con\u00e7u pour rationaliser ce processus et garantir l&rsquo;efficacit\u00e9 et la fiabilit\u00e9 de la gestion des fichiers.<\/p>\n<h2>Contexte<\/h2>\n<p>Ce script est particuli\u00e8rement utile pour les professionnels de l&rsquo;informatique qui doivent v\u00e9rifier r\u00e9guli\u00e8rement l&rsquo;existence de fichiers ou de dossiers critiques. Il fournit une <a href=\"https:\/\/www.ninjaone.com\/fr\/blog\/tout-ce-que-vous-devez-savoir-sur-lautomatisation\/\" target=\"_blank\" rel=\"noopener\">solution automatis\u00e9e<\/a> pour effectuer des recherches dans les r\u00e9pertoires, en s&rsquo;assurant que les fichiers importants sont pr\u00e9sents ou en identifiant leur absence. Cette capacit\u00e9 est cruciale dans divers sc\u00e9narios, tels que la validation des emplacements de sauvegarde, la garantie de la pr\u00e9sence de fichiers de configuration ou la confirmation du d\u00e9ploiement d&rsquo;applications critiques.<\/p>\n<h2>Le script<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/usr\/bin\/env bash\r\n\r\n# Description: Alert if a specified file or folder is found in a directory or subdirectory you specify.\r\n#\r\n# Release Notes: Initial Release\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# Below are all the (case sensitive) valid parameters for this script.\r\n# Only the path to search and name of file or folder are required!\r\n#\r\n# Parameter: --path \"\/opt\/NinjaRMM\/programdata\"\r\n#   Required\r\n#   Base path to search for files or folders.\r\n#\r\n# Parameter: --name \"ninjarmm-cli\"\r\n#   Required\r\n#   Name of the file or folder to search for.\r\n#   Notes:\r\n#       If the name is not provided, the script will search for the path only.\r\n#       This is case sensitive and accepts wildcards.\r\n#\r\n# Parameter: --type \"Files Or Folders\"\r\n#   Required\r\n#   Search for files or folders.\r\n#\r\n# Parameter: --type \"Files Only\"\r\n#   Required\r\n#   Searches for files only.\r\n#\r\n# Parameter: --type \"Folders Only\"\r\n#   Required\r\n#   Searches for folder only.\r\n#\r\n# Parameter: --timeout 10\r\n#   Optional and defaults to 30 minutes\r\n#   Time in minutes to wait for the search to complete before timing out.\r\n#\r\n# Parameter: --customfield \"myCustomField\"\r\n#   Optional\r\n#   Custom Field to save the search results to.\r\n\r\ndie() {\r\n    local _ret=\"${2:-1}\"\r\n    test \"${_PRINT_HELP:-no}\" = yes &amp;&amp; print_help &gt;&amp;2\r\n    echo \"$1\" &gt;&amp;2\r\n    exit \"${_ret}\"\r\n}\r\n\r\nbegins_with_short_option() {\r\n    local first_option all_short_options='h'\r\n    first_option=\"${1:0:1}\"\r\n    test \"$all_short_options\" = \"${all_short_options\/$first_option\/}\" &amp;&amp; return 1 || return 0\r\n}\r\n\r\n# Initize arguments\r\n_arg_path=\r\n_arg_name=\r\n_arg_type=\r\n_arg_timeout=30\r\n_arg_customfield=\r\n\r\nprint_help() {\r\n    printf '%s\\n' \"Check existence of a file or folder\"\r\n    printf 'Usage: %s [--path &lt;arg&gt;] [--name &lt;arg&gt;] [--type &lt;\"Files Only\"|\"Folders Only\"|\"Files Or Folders\"&gt;] [--timeout &lt;30&gt;] [--customfield &lt;arg&gt;] [-h|--help]\\n' \"$0\"\r\n    printf '\\t%s\\n' \"-h, --help: Prints help\"\r\n}\r\n\r\nparse_commandline() {\r\n    while test $# -gt 0; do\r\n        _key=\"$1\"\r\n        case \"$_key\" in\r\n        --path)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_path=\"$2\"\r\n            shift\r\n            ;;\r\n        --path=*)\r\n            _arg_path=\"${_key##--path=}\"\r\n            ;;\r\n        --name)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_name=\"$2\"\r\n            shift\r\n            ;;\r\n        --name=*)\r\n            _arg_name=\"${_key##--name=}\"\r\n            ;;\r\n        --type)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_type=\"$2\"\r\n            shift\r\n            ;;\r\n        --type=*)\r\n            _arg_type=\"${_key##--type=}\"\r\n            ;;\r\n        --timeout)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_timeout=\"$2\"\r\n            shift\r\n            ;;\r\n        --timeout=*)\r\n            _arg_timeout=\"${_key##--timeout=}\"\r\n            ;;\r\n        --customfield)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_customfield=\"$2\"\r\n            shift\r\n            ;;\r\n        --customfield=*)\r\n            _arg_customfield=\"${_key##--customfield=}\"\r\n            ;;\r\n        -h | --help)\r\n            print_help\r\n            exit 0\r\n            ;;\r\n        -h*)\r\n            print_help\r\n            exit 0\r\n            ;;\r\n        *)\r\n            _PRINT_HELP=yes die \"FATAL ERROR: Got an unexpected argument '$1'\" 1\r\n            ;;\r\n        esac\r\n        shift\r\n    done\r\n}\r\n\r\nparse_commandline \"$@\"\r\n\r\nfunction SetCustomField() {\r\n    customfieldName=$1\r\n    customfieldValue=$2\r\n    if [ -f \"${NINJA_DATA_PATH}\/ninjarmm-cli\" ]; then\r\n        if [ -x \"${NINJA_DATA_PATH}\/ninjarmm-cli\" ]; then\r\n            if \"$NINJA_DATA_PATH\"\/ninjarmm-cli get \"$customfieldName\" &gt;\/dev\/null; then\r\n                # check if the value is greater than 10000 characters\r\n                if [ ${#customfieldValue} -gt 10000 ]; then\r\n                    echo \"[Warn] Custom field value is greater than 10000 characters\"\r\n                fi\r\n                if ! echo \"${customfieldValue::10000}\" | \"$NINJA_DATA_PATH\"\/ninjarmm-cli set --stdin \"$customfieldName\"; then\r\n                    echo \"[Warn] Failed to set custom field\"\r\n                else\r\n                    echo \"[Info] Custom field value set successfully\"\r\n                fi\r\n            else\r\n                echo \"[Warn] Custom Field ($customfieldName) does not exist or agent does not have permission to access it\"\r\n            fi\r\n        else\r\n            echo \"[Warn] ninjarmm-cli is not executable\"\r\n        fi\r\n    else\r\n        echo \"[Warn] ninjarmm-cli does not exist\"\r\n    fi\r\n}\r\n\r\nif [ ! \"$(command -v timeout)\" ]; then\r\n    notimeout=true\r\n    # If the timeout command does not exist, create a function to mimic the timeout command\r\n    function timeout() { perl -e 'alarm shift; exec @ARGV' \"$@\"; }\r\nfi\r\n\r\nparentSearchPath=$_arg_path\r\nleafSearchName=$_arg_name\r\nsearchType=$_arg_type\r\ntimeout=$_arg_timeout\r\ncustomField=$_arg_customfield\r\n\r\n# Get values from Script Variables\r\nif [[ -n \"${pathToSearch}\" ]]; then\r\n    parentSearchPath=\"${pathToSearch}\"\r\nfi\r\nif [[ -n \"${nameOfFileOrFolder}\" ]]; then\r\n    leafSearchName=\"${nameOfFileOrFolder}\"\r\nfi\r\nif [[ -n \"${filesOrFolders}\" &amp;&amp; \"${filesOrFolders}\" != \"null\" ]]; then\r\n    searchType=\"${filesOrFolders}\"\r\nfi\r\nif [[ -n \"${searchTimeout}\" &amp;&amp; \"${searchTimeout}\" != \"null\" ]]; then\r\n    timeout=\"${searchTimeout}\"\r\nfi\r\nif [[ -n \"${customFieldName}\" &amp;&amp; \"${customFieldName}\" != \"null\" ]]; then\r\n    customField=\"${customFieldName}\"\r\nfi\r\n\r\n# Check if parentSearchPath is a link and replace it with the resolved path\r\nif [ -L \"${parentSearchPath}\" ]; then\r\n    echo \"[Info] Path to Search is a link: ${parentSearchPath} -&gt; $(readlink -f \"${parentSearchPath}\")\"\r\n    echo \"[Info] Will use the resolved path to search\"\r\n    parentSearchPath=$(readlink -f \"${parentSearchPath}\")\r\nfi\r\n\r\nif [[ -z \"${parentSearchPath}\" ]]; then\r\n    echo \"[Error] Path to Search is empty\"\r\n    exit 1\r\nfi\r\n\r\n# Check if path exists\r\nif [ -e \"${parentSearchPath}\" ]; then\r\n    echo \"[Info] Path ${parentSearchPath} exists\"\r\nelse\r\n    echo \"[Error] Path to Search ${parentSearchPath} does not exist or is an invalid path\"\r\n    exit 1\r\nfi\r\n\r\n# Check if timeout is a number\r\nif ! [[ \"${timeout}\" =~ ^[0-9]+$ ]]; then\r\n    echo \"[Error] Timeout is not a number\"\r\n    exit 1\r\nfi\r\n# Check if timeout is not in the range of 1 to 120\r\nif [[ \"${timeout}\" -lt 1 || \"${timeout}\" -gt 120 ]]; then\r\n    echo \"[Error] Timeout is not in the range of 1 to 120\"\r\n    exit 1\r\nfi\r\n\r\n# Check if search type is valid\r\n\r\nif $notimeout; then\r\n    # If the timeout command does not exist, convert the timeout to minutes\r\n    timeout=$((timeout * 60))\r\nelse\r\n    # If the timeout command does exist, add m to the end of the string\r\n    timeout=\"${timeout}m\"\r\nfi\r\n\r\nif [[ $OSTYPE == 'darwin'* ]]; then\r\n    if ! plutil -lint \/Library\/Preferences\/com.apple.TimeMachine.plist &gt;\/dev\/null; then\r\n        echo \"This script requires ninjarmm-macagent to have Full Disk Access.\"\r\n        echo \"Add ninjarmm-macagent to the Full Disk Access list in System Preferences &gt; Security &amp; Privacy, quit the app, and re-run this script.\"\r\n        exit 1\r\n    fi\r\nfi\r\n\r\n# Search for files or folders\r\nif [[ -n \"${leafSearchName}\" &amp;&amp; \"${leafSearchName}\" != \"null\" ]]; then\r\n    if [[ \"${searchType}\" == *\"Files\"* &amp;&amp; \"${searchType}\" == *\"Only\"* ]]; then\r\n        echo \"[Info] Searching for files only\"\r\n        # Search for files only\r\n        # Use timeout to prevent the find command from running indefinitely\r\n        foundPath=$(timeout \"${timeout}\" find \"$parentSearchPath\" -type f -name \"$leafSearchName\" 2&gt;\/dev\/null)\r\n        exitcode=$?\r\n        if [[ $exitcode -eq 0 || $exitcode -eq 124 ]]; then\r\n            if [[ -n $foundPath ]]; then\r\n                echo \"[Alert] File Found\"\r\n            fi\r\n        fi\r\n    elif [[ \"${searchType}\" == *\"Folders\"* &amp;&amp; \"${searchType}\" == *\"Only\"* ]]; then\r\n        echo \"[Info] Searching for folders only\"\r\n        # Search for folders only\r\n        # Use timeout to prevent the find command from running indefinitely\r\n        foundPath=$(timeout \"${timeout}\" find \"$parentSearchPath\" -type d -name \"$leafSearchName\" 2&gt;\/dev\/null)\r\n        exitcode=$?\r\n        if [[ $exitcode -eq 0 || $exitcode -eq 124 ]]; then\r\n            if [[ -n $foundPath ]]; then\r\n                echo \"[Alert] File Found\"\r\n            fi\r\n        fi\r\n    elif [[ \"${searchType}\" == *\"Files\"* &amp;&amp; \"${searchType}\" == *\"Folders\"* ]]; then\r\n        echo \"[Info] Searching for files or folders\"\r\n        # Search for files or folders\r\n        # Use timeout to prevent the find command from running indefinitely\r\n        foundPath=$(timeout \"${timeout}\" find \"$parentSearchPath\" -name \"$leafSearchName\" 2&gt;\/dev\/null)\r\n        exitcode=$?\r\n        if [[ $exitcode -eq 0 || $exitcode -eq 124 ]]; then\r\n            if [[ -n $foundPath ]]; then\r\n                echo \"[Alert] File Found\"\r\n            fi\r\n        fi\r\n    else\r\n        echo \"[Error] Invalid search type\"\r\n        echo \"Valid search types: Files Only, Folders Only, Files Or Folders\"\r\n        exit 1\r\n    fi\r\nelif [[ -z \"${leafSearchName}\" ]]; then\r\n    echo \"[Info] Searching in path only\"\r\n    # Search in path only\r\n    # Use timeout to prevent the find command from running indefinitely\r\n    foundPath=$(timeout \"${timeout}\" find \"$parentSearchPath\")\r\n    exitcode=$?\r\n    if [[ $exitcode -eq 0 || $exitcode -eq 124 ]]; then\r\n        if [[ -n $foundPath ]]; then\r\n            echo \"[Alert] File Found\"\r\n        fi\r\n    fi\r\nfi\r\n\r\n# Check exit code\r\nif [[ -n $foundPath ]]; then\r\n    # Split the string into an array\r\n    IFS=$'\\n' read -rd '' -a foundPathArray &lt;&lt;&lt;\"${foundPath}\"\r\n    # Print each element of the array\r\n    for element in \"${foundPathArray[@]}\"; do\r\n        echo \"[Alert] ${element} exists\"\r\n    done\r\nelif [[ -z $foundPath ]]; then\r\n    echo \"[Warn] Could not find a file or folder\"\r\n    exit 1\r\nelse\r\n    # If the find command fails to find the file or folder\r\n\r\n    # Figure out the grammer for the search type\r\n    if [[ \"${searchType}\" == *\"Only\"* ]]; then\r\n        if [[ \"${searchType}\" == *\"Files\"* ]]; then\r\n            searchTypeInfo=\"file\"\r\n        elif [[ \"${searchType}\" == *\"Folders\"* ]]; then\r\n            searchTypeInfo=\"folder\"\r\n        fi\r\n    elif [[ \"${searchType}\" == *\"Files\"* &amp;&amp; \"${searchType}\" == *\"Folders\"* ]]; then\r\n        searchTypeInfo=\"file or folder\"\r\n    fi\r\n    echo \"[Info] Could not find a ${searchTypeInfo} in the path ${parentSearchPath} with the name containing: ${leafSearchName}\"\r\nfi\r\n\r\n# If foundPath contains \"Alarm clock:\" then the command timed out\r\nif [[ \"${foundPath}\" == *\"Alarm clock:\"* ]]; then\r\n    echo \"[Alert] Timed out searching for file or folder\"\r\n    # Remove \"Alarm clock: *\" from the string\r\n    foundPath=${foundPath\/Alarm clock: [0-9]*\/\/}\r\nfi\r\n\r\n# If command times out\r\nif [[ $exitcode -ge 124 &amp;&amp; $exitcode -le 127 || $exitcode -eq 137 ]]; then\r\n    echo \"[Alert] Timed out searching for file or folder\"\r\n    echo \"timeout exit code: $exitcode\"\r\n    echo \"  124  if COMMAND times out, and --preserve-status is not specified\"\r\n    echo \"  125  if the timeout command itself fails\"\r\n    echo \"  126  if COMMAND is found but cannot be invoked\"\r\n    echo \"  127  if COMMAND cannot be found\"\r\n    echo \"  137  if COMMAND (or timeout itself) is sent the KILL (9) signal (128+9)\"\r\n    echo \"find command result: $foundPath\"\r\n    exit 1\r\nfi\r\n\r\n# Save to custom field\r\nif [[ -n \"${customField}\" &amp;&amp; \"${customField}\" != \"null\" ]]; then\r\n    SetCustomField \"${customField}\" \"${foundPath}\"\r\nfi<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><\/div>\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Le script fonctionne en prenant plusieurs param\u00e8tres pour personnaliser le processus de recherche. Voici une description d\u00e9taill\u00e9e de ses fonctionnalit\u00e9s :<\/p>\n<p><strong>1. Param\u00e8tres et initialisation<\/strong>:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"2\"><strong>&#8211;path<\/strong>: Sp\u00e9cifie le r\u00e9pertoire de base dans lequel la recherche doit \u00eatre effectu\u00e9e.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"2\"><strong>&#8211;name<\/strong>: D\u00e9finit le nom du fichier ou du dossier \u00e0 rechercher, avec des caract\u00e8res g\u00e9n\u00e9riques.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"2\"><strong>&#8211;type<\/strong>: D\u00e9termine si la recherche doit porter sur les fichiers, les dossiers ou les deux.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"2\"><strong>&#8211;timeout<\/strong>: D\u00e9finit la dur\u00e9e maximale de l&rsquo;op\u00e9ration de recherche, fix\u00e9e par d\u00e9faut \u00e0 30 minutes.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"2\"><strong>&#8211;customfield<\/strong>: Permet d&rsquo;enregistrer le r\u00e9sultat de la recherche dans un champ personnalis\u00e9.<\/li>\n<\/ul>\n<p><strong>2. Analyse des arguments<\/strong>: Le script analyse les arguments de la ligne de commande pour initialiser les param\u00e8tres de recherche. Si l&rsquo;un des param\u00e8tres requis est manquant, il envoie un message d&rsquo;erreur et quitte le syst\u00e8me.<\/p>\n<p><strong>3. Ex\u00e9cution de la recherche<\/strong>:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"2\">Le script r\u00e9sout tous les liens symboliques dans le chemin de recherche.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"2\">Il v\u00e9rifie que le chemin sp\u00e9cifi\u00e9 existe et qu&rsquo;il est valide.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"2\">Il s&rsquo;assure que le d\u00e9lai d&rsquo;attente se situe dans la plage acceptable (1 \u00e0 120 minutes).<\/li>\n<\/ul>\n<p><strong>4. Recherche de fichiers ou de dossiers<\/strong>: En fonction du type sp\u00e9cifi\u00e9 (fichiers, dossiers ou les deux), le script utilise la commande find avec un d\u00e9lai d&rsquo;attente pour localiser les \u00e9l\u00e9ments souhait\u00e9s. S&rsquo;il est trouv\u00e9, il alerte l&rsquo;utilisateur et enregistre \u00e9ventuellement le r\u00e9sultat dans un champ personnalis\u00e9.<\/p>\n<p><strong>5. Gestion des erreurs et rapports<\/strong>: Le script comprend une gestion compl\u00e8te des erreurs, garantissant que les probl\u00e8mes tels que les chemins d&rsquo;acc\u00e8s non valides, les valeurs de d\u00e9lai d&rsquo;attente incorrectes ou les fichiers\/dossiers inexistants sont clairement signal\u00e9s \u00e0 l&rsquo;utilisateur.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<h3>\u00c9tude de cas\u00a0: V\u00e9rification de la conformit\u00e9 des technologies de l&rsquo;information<\/h3>\n<p>Un professionnel de l&rsquo;informatique est charg\u00e9 de veiller \u00e0 ce que les fichiers de configuration de s\u00e9curit\u00e9 essentiels soient pr\u00e9sents sur tous les serveurs. Gr\u00e2ce \u00e0 ce script, ils peuvent automatiser le processus de v\u00e9rification :<\/p>\n<p><strong>1. Setup<\/strong>:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"9\" data-aria-level=\"2\">&#8211;<strong>-chemin<\/strong>: \/etc\/security<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"10\" data-aria-level=\"2\">&#8212;<strong>nom<\/strong>: security.conf<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"11\" data-aria-level=\"2\"><strong>&#8211;type<\/strong>: Fichiers uniquement<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"12\" data-aria-level=\"2\"><strong>&#8211;timeout<\/strong>: 10<\/li>\n<\/ul>\n<p><strong>2. Ex\u00e9cution<\/strong>\u00a0: Le script recherche le fichier security.conf dans le chemin sp\u00e9cifi\u00e9 pendant le d\u00e9lai fix\u00e9. S&rsquo;il est d\u00e9tect\u00e9, il enregistre une alerte ; s&rsquo;il ne l&rsquo;est pas, il avertit le professionnel de l&rsquo;informatique, ce qui permet de rem\u00e9dier rapidement \u00e0 la situation.<\/p>\n<h2>Comparaisons<\/h2>\n<p>Par rapport \u00e0 une v\u00e9rification manuelle ou \u00e0 l&rsquo;utilisation de commandes shell de base, ce script pr\u00e9sente plusieurs avantages :<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Automatisation<\/strong>\u00a0: R\u00e9duit la n\u00e9cessit\u00e9 d&rsquo;effectuer des contr\u00f4les manuels.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Gestion des d\u00e9lais<\/strong>: Emp\u00eache les recherches prolong\u00e9es en imposant un d\u00e9lai d&rsquo;attente.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Rapports personnalis\u00e9s<\/strong>: Permet d&rsquo;enregistrer les r\u00e9sultats dans des champs personnalis\u00e9s en vue d&rsquo;un traitement ult\u00e9rieur ou d&rsquo;un rapport de conformit\u00e9.<\/li>\n<\/ul>\n<p>D&rsquo;autres m\u00e9thodes, comme l&rsquo;utilisation des commandes ls ou test dans Bash, ne disposent pas de ces fonctionnalit\u00e9s avanc\u00e9es, ce qui fait de ce script une solution plus robuste et plus efficace.<\/p>\n<h2>FAQ<\/h2>\n<ol>\n<li><strong> Que se passe-t-il si le script n&rsquo;aboutit pas ?<\/strong><br \/>\nLe script signale un d\u00e9passement de d\u00e9lai et se termine avec un code d&rsquo;erreur appropri\u00e9, ce qui permet \u00e0 l&rsquo;utilisateur de savoir que la recherche \u00e9tait incompl\u00e8te.<\/li>\n<li><strong> Puis-je rechercher plusieurs types de fichiers simultan\u00e9ment ?<\/strong><br \/>\nNon, le script prend actuellement en charge la recherche de fichiers ou de dossiers sur la base d&rsquo;un seul mod\u00e8le de nom \u00e0 la fois.<\/li>\n<li><strong> Comment g\u00e9rer les liens symboliques dans le chemin de recherche ?<\/strong><br \/>\nLe script r\u00e9sout automatiquement les liens symboliques, ce qui garantit que la recherche est effectu\u00e9e dans le bon r\u00e9pertoire.<\/li>\n<\/ol>\n<h2>Implications<\/h2>\n<p>L&rsquo;utilisation de ce script peut am\u00e9liorer consid\u00e9rablement la s\u00e9curit\u00e9 informatique en garantissant la pr\u00e9sence des fichiers et dossiers critiques. La v\u00e9rification automatis\u00e9e contribue \u00e0 maintenir la conformit\u00e9 avec les politiques de s\u00e9curit\u00e9 et r\u00e9duit le risque de manquer des fichiers importants, ce qui pourrait entra\u00eener des vuln\u00e9rabilit\u00e9s ou des d\u00e9faillances du syst\u00e8me.<\/p>\n<h2>Recommandations<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Audits r\u00e9guliers<\/strong>: Planifiez l&rsquo;ex\u00e9cution r\u00e9guli\u00e8re du script afin de maintenir \u00e0 jour la v\u00e9rification des fichiers critiques.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\"><strong>Utilisation de champs personnalis\u00e9s<\/strong>: Tirez parti de l&rsquo;option des champs personnalis\u00e9s pour suivre les r\u00e9sultats de la recherche et en rendre compte de mani\u00e8re syst\u00e9matique.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"1\"><strong>Param\u00e8tres du d\u00e9lai d&rsquo;attente<\/strong>: Ajustez le param\u00e8tre de d\u00e9lai d&rsquo;attente en fonction de la taille pr\u00e9vue du r\u00e9pertoire et des performances du syst\u00e8me afin d&rsquo;\u00e9viter les retards inutiles.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Ce script Bash est un outil puissant pour les professionnels de l&rsquo;informatique. Il fournit une m\u00e9thode automatis\u00e9e et fiable pour v\u00e9rifier l&rsquo;existence de fichiers et de dossiers. En int\u00e9grant ce script dans les contr\u00f4les de routine, les MSP peuvent garantir une <a href=\"https:\/\/www.ninjaone.com\/fr\/efficacite\" target=\"_blank\" rel=\"noopener\">efficacit\u00e9<\/a> et une <a href=\"https:\/\/www.ninjaone.com\/fr\/top-5-des-principes-fondamentaux-de-securite-informatique\/\" target=\"_blank\" rel=\"noopener\">s\u00e9curit\u00e9<\/a> accrues dans leurs op\u00e9rations. Des outils tels que <a href=\"https:\/\/www.ninjaone.com\/fr\/\" target=\"_blank\" rel=\"noopener\">NinjaOne<\/a> peuvent encore am\u00e9liorer ce processus en offrant des solutions de gestion informatique compl\u00e8tes, facilitant le d\u00e9ploiement, la surveillance et la gestion des scripts sur plusieurs syst\u00e8mes.<\/p>\n<p>L&rsquo;automatisation de la gestion des dossiers permet non seulement de gagner du temps, mais aussi d&rsquo;am\u00e9liorer la pr\u00e9cision, en veillant \u00e0 ce que les dossiers essentiels se trouvent toujours l\u00e0 o\u00f9 ils doivent \u00eatre.<\/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":"","_lmt_disable":""},"operating_system":[4210],"use_cases":[4285],"class_list":["post-353648","script_hub","type-script_hub","status-publish","hentry","script_hub_category-macos","use_cases-surveillance"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/353648","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=353648"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=353648"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=353648"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=353648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}