{"id":385366,"date":"2024-11-21T08:31:48","date_gmt":"2024-11-21T08:31:48","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=385366"},"modified":"2024-11-21T08:31:48","modified_gmt":"2024-11-21T08:31:48","slug":"ueberpruefung-des-vorhandenseins-von-dateien","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/de\/script-hub\/ueberpruefung-des-vorhandenseins-von-dateien\/","title":{"rendered":"Vollst\u00e4ndiger Guide: Wie man mit einem Linux-Skript das Vorhandensein von Dateien oder Ordnern \u00fcberpr\u00fcft"},"content":{"rendered":"<p>Die Sicherstellung der Integrit\u00e4t und des Vorhandenseins wichtiger Dateien und Verzeichnisse ist f\u00fcr die IT-Verwaltung von gr\u00f6\u00dfter Bedeutung. Egal, ob Sie ein IT-Experte oder ein <a href=\"https:\/\/www.ninjaone.com\/de\/was-ist-ein-msp\" target=\"_blank\" rel=\"noopener\">Managed Service Provider (MSP)<\/a> sind, das Verfolgen wichtiger Systemdateien oder spezifischer Anwendungsordner kann dazu beitragen, die Systemstabilit\u00e4t, Sicherheit und Compliance aufrechtzuerhalten. Hier kommen Automatisierungsskripte ins Spiel, insbesondere eines, das Sie benachrichtigt, wenn <strong>eine bestimmte Datei oder ein bestimmter Ordner<\/strong> in einem Verzeichnis oder Unterverzeichnis <strong>gefunden wird<\/strong>.<\/p>\n<h2>Kontext<\/h2>\n<p>Das vorgestellte Skript bietet eine zuverl\u00e4ssige L\u00f6sung f\u00fcr die Suche und Benachrichtigung auf der Grundlage des Vorhandenseins von Dateien oder Ordnern innerhalb eines bestimmten Pfads. Diese Art der Automatisierung ist in verschiedenen Szenarien ausschlaggebend, z. B. bei der \u00dcberpr\u00fcfung der erfolgreichen Bereitstellung, der \u00dcberwachung nicht autorisierter \u00c4nderungen oder der Sicherstellung kritischer Konfigurationen. F\u00fcr IT-Experten und MSPs kann der Einsatz solcher Skripte die betriebliche Effizienz steigern und den manuellen \u00dcberwachungsaufwand reduzieren.<\/p>\n<h2>Das Skript zur \u00dcberpr\u00fcfung des Vorhandenseins von Dateien und Ordnern<\/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\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\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# 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}m\" 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}m\" 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}m\" 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    # Search in path only\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}m\" 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    if [[ -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\n    elif [[ -z \"${foundPath}\" ]]; then\r\n        echo \"[Info] ${foundPath} does not exist\"\r\n    fi\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 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\"><p>Greifen Sie auf \u00fcber 300 Skripte im NinjaOne Dojo zu.<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/de\/kostenlosetestversionformular\/\">Zugang erhalten<\/a><\/p>\n<\/div>\n<h2>Detailansicht<\/h2>\n<p>Schauen wir uns das Skript genauer an, um seine Funktionsweise, Parameter und Funktionen zu verstehen:<\/p>\n<h3>Parameter und Optionen<\/h3>\n<p>Das Skript akzeptiert mehrere Parameter, um den Suchvorgang anzupassen:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\">&#8211;path &#8218;\/opt\/NinjaRMM\/programdata&#8216;: Gibt den Basispfad f\u00fcr die Suche nach Dateien oder Ordnern an. Dieser Parameter ist erforderlich.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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\">&#8211;name &#8217;ninjarmm-cli&#8216;: Legt den Namen der Datei oder des Ordners fest, nach dem gesucht werden soll. Dies ist ebenfalls erforderlich und unterst\u00fctzt Gro\u00df- und Kleinschreibung sowie Wildcard-Zeichen.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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\">&#8211;type &#8218;Files Or Folders&#8216;: Legt fest, ob nach Dateien, Ordnern oder beidem gesucht werden soll. Erforderlicher Parameter mit Optionen:<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"2\">Files Only<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"2\">Folders Only<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"2\">Files Or Folders<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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\">&#8211;timeout 10: Ein optionaler Parameter, der die Zeit (in Minuten) angibt, die auf den Abschluss der Suche gewartet werden soll, bevor die Suche abgebrochen wird; der Standardwert ist 30 Minuten.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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\">&#8211;customfield &#8218;myCustomField&#8216;: Ein optionaler Parameter zum Speichern der Suchergebnisse in einem benutzerdefinierten Feld.<\/li>\n<\/ul>\n<h3>Ablauf der Skriptausf\u00fchrung<\/h3>\n<p><strong>1. Initialisierung und Argumente-Parsen:<\/strong> Das Skript beginnt mit der Definition von Hilfsfunktionen (&#8218;die&#8216; und &#8218;begins_with_short_option&#8216;) und der Initialisierung von Argumentvariablen. Die Funktion &#8218;parse_commandline&#8216; verarbeitet die angegebenen Argumente, validiert sie und weist sie den entsprechenden Variablen zu.<\/p>\n<p><strong>2. Die Funktion &#8218;SetCustomField&#8216;:<\/strong> Diese Funktion setzt ein benutzerdefiniertes Feld mit den Suchergebnissen, wenn das Tool &#8217;ninjarmm-cli&#8216; verf\u00fcgbar und ausf\u00fchrbar ist. Es pr\u00fcft verschiedene Bedingungen, z. B. das Vorhandensein des Tools und des benutzerdefinierten Feldes, und behandelt die Beschr\u00e4nkungen der Wertl\u00e4nge.<\/p>\n<p><strong>3. Hauptlogik:<\/strong><\/p>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"2\">Das Skript \u00fcberpr\u00fcft den erforderlichen Pfadparameter und sorgt daf\u00fcr, dass das angegebene Verzeichnis existiert.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"2\">Es wird gepr\u00fcft, ob der Timeout-Wert innerhalb des zul\u00e4ssigen Bereichs (1 bis 120 Minuten) liegt.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"2\">Je nach angegebenem Typ (&#8218;Files Only&#8216;, &#8218;Folders Only&#8216;, &#8218;Files Or Folders&#8216;) wird die Suche mit dem Befehl &#8218;find&#8216; durchgef\u00fchrt, wobei eine Zeit\u00fcberschreitung vorgesehen ist, um eine unendliche Ausf\u00fchrung zu verhindern.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"2\">Die Suchergebnisse werden entsprechend gehandhabt, wobei das Skript eine Warnmeldung ausgibt, wenn die Datei oder der Ordner gefunden wird, und speichert die Ergebnisse in einem benutzerdefinierten Feld, falls dies angegeben wurde.<\/li>\n<\/ul>\n<h2>Potenzielle Anwendungsf\u00e4lle<\/h2>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>\u00dcberpr\u00fcfung der Bereitstellung:<\/strong> Es wird sichergestellt, dass kritische Dateien nach der Bereitstellung vorhanden sind, um die erfolgreiche Installation der Anwendung zu best\u00e4tigen.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Sicherheits\u00fcberwachung:<\/strong> Man kann nicht autorisierte Datei- oder Verzeichniserg\u00e4nzungen erkennen, die auf eine Sicherheitsverletzung oder einen Versto\u00df gegen die Richtlinien hinweisen k\u00f6nnten.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Compliance-Audits:<\/strong> Es wird auf das Vorhandensein der notwendigen Konfigurationsdateien oder Protokolle \u00fcberpr\u00fcft, die f\u00fcr die Einhaltung der Industriestandards erforderlich sind.<\/li>\n<\/ol>\n<h2>Hypothetische Fallstudie<\/h2>\n<p>Stellen Sie sich vor, ein MSP verwaltet mehrere Kundenumgebungen. Durch das Ausrollen dieses Skripts auf den Kundensystemen kann der MSP den \u00dcberpr\u00fcfungsprozess wichtiger Dateien, wie z. B. Antivirendefinitionen oder Systemkonfigurationen, automatisieren. Auf diese Weise sorgt er daf\u00fcr, dass sie aktuell sind und den Sicherheitsrichtlinien entsprechen. Werden Unstimmigkeiten festgestellt, benachrichtigt das Skript den MSP und erm\u00f6glicht so eine schnelle Probleml\u00f6sung.<\/p>\n<h2>Vergleiche<\/h2>\n<p>Herk\u00f6mmliche Methoden zur \u00dcberpr\u00fcfung des Vorhandenseins von Dateien umfassen manuelle Befehle oder einfache Skripte, denen es an robuster Fehlerbehandlung und Anpassungsoptionen mangelt. Das mitgelieferte Skript zeichnet sich durch eine umfassende Parametrisierung, Timeout-Verwaltung und die Integration von benutzerdefinierten Feldern zur Ergebnisspeicherung aus. Dieses Ma\u00df an Automatisierung und Flexibilit\u00e4t steigert die betriebliche Effizienz erheblich.<\/p>\n<h2>FAQs<\/h2>\n<h3>F: Kann dieses Skript nach mehreren Dateien oder Ordnern auf einmal suchen?<\/h3>\n<p>A: Nein, das Skript ist f\u00fcr die Suche nach einer einzelnen angegebenen Datei oder einem Ordner konzipiert. Mehrere Suchvorg\u00e4nge w\u00fcrden mehrere Skriptausf\u00fchrungen erfordern.<\/p>\n<h3>F: Wie geht das Skript mit gro\u00dfen Verzeichnissen um?<\/h3>\n<p>A: Das Skript verwendet den Befehl &#8218;find&#8216; mit einer Zeit\u00fcberschreitung, um langwierige Suchen zu verhindern. Dadurch wird sichergestellt, dass es in gro\u00dfen Verzeichnissen nicht unendlich lange h\u00e4ngen bleibt.<\/p>\n<h3>F: Was passiert, wenn das Tool &#8217;ninjarmm-cli&#8216; nicht verf\u00fcgbar ist?<\/h3>\n<p>A: Das Skript gibt eine Warnmeldung aus und setzt seine Arbeit fort. Die Funktionalit\u00e4t der benutzerdefinierten Felder w\u00fcrde \u00fcbersprungen, wenn das Tool nicht ausf\u00fchrbar ist.<\/p>\n<h2>Folgen<\/h2>\n<p>Die M\u00f6glichkeit, die \u00dcberpr\u00fcfung auf die Existenz von Dateien und Ordnern zu automatisieren, hat erhebliche Auswirkungen auf die IT-Sicherheit und -Verwaltung. Automatische Warnmeldungen helfen dabei, nicht autorisierte \u00c4nderungen, <a href=\"https:\/\/www.ninjaone.com\/it-hub\/endpoint-security\/what-is-a-data-breach\/\" target=\"_blank\" rel=\"noopener\">potenzielle Sicherheitsverletzungen<\/a> und Compliance-Probleme schnell zu erkennen. Dieser proaktive Ansatz erh\u00f6ht die Sicherheit und Zuverl\u00e4ssigkeit des gesamten Systems.<\/p>\n<h2>Empfehlungen<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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>Angemessene Timeouts einstellen:<\/strong> Vergewissern Sie sich, dass der Timeout-Wert realistisch f\u00fcr die Verzeichnisgr\u00f6\u00dfe ist, um unn\u00f6tige Skriptabbr\u00fcche zu vermeiden.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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>Regelm\u00e4\u00dfige Aktualisierung der Suchkriterien:<\/strong> Passen Sie die Suchparameter an sich \u00e4ndernde Anforderungen an, z. B. neue kritische Dateien oder Verzeichnisse.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" 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=\"8\" data-aria-level=\"1\"><strong>Integration mit \u00dcberwachungssystemen:<\/strong> Nutzen Sie die Funktionalit\u00e4t der benutzerdefinierten Felder f\u00fcr die Integration in umfassendere \u00dcberwachungs- und Warnsysteme, um einen einheitlichen \u00dcberblick \u00fcber den Systemzustand und die Compliance zu erhalten.<\/li>\n<\/ul>\n<h2>Abschlie\u00dfende \u00dcberlegungen<\/h2>\n<p>Automatisierungsskripte wie das hier beschriebene sind unsch\u00e4tzbare Tools f\u00fcr IT-Experten und MSPs. Sie bieten eine zuverl\u00e4ssige und <a href=\"https:\/\/www.ninjaone.com\/de\/effizienz\/\" target=\"_blank\" rel=\"noopener\">effiziente M\u00f6glichkeit<\/a>, um sicherzustellen, dass wichtige Dateien und Verzeichnisse vorhanden und korrekt sind. Wenn Sie dieses Skript in Ihre IT-Verwaltungspraktiken integrieren, k\u00f6nnen Sie <a href=\"https:\/\/www.ninjaone.com\/de\/top-5-it-sicherheitsgrundlagen\" target=\"_blank\" rel=\"noopener\">die Sicherheit<\/a>, die Einhaltung von Vorschriften und die betriebliche Effizienz <a href=\"https:\/\/www.ninjaone.com\/de\/top-5-it-sicherheitsgrundlagen\" target=\"_blank\" rel=\"noopener\">verbessern<\/a>. <a href=\"https:\/\/www.ninjaone.com\/de\/\" target=\"_blank\" rel=\"noopener\">NinjaOne<\/a> bietet eine Reihe von Tools an, die solche Skripte erg\u00e4nzen und umfassende, auf Ihre Bed\u00fcrfnisse zugeschnittene IT-Management-L\u00f6sungen bereitstellen k\u00f6nnen.<\/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":[4383],"class_list":["post-385366","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub\/385366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/comments?post=385366"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media?parent=385366"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/operating_system?post=385366"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/use_cases?post=385366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}