{"id":353654,"date":"2024-08-27T09:40:39","date_gmt":"2024-08-27T09:40:39","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/creer-des-pop-up-linux\/"},"modified":"2024-10-13T19:08:27","modified_gmt":"2024-10-13T19:08:27","slug":"creer-des-pop-up-linux","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/creer-des-pop-up-linux\/","title":{"rendered":"Comment cr\u00e9er des pop-up sur Linux de fa\u00e7on efficace pour les professionnels de l&rsquo;informatique et les MSP"},"content":{"rendered":"<p>Une communication efficace est vitale pour les professionnels de l&rsquo;informatique, en particulier lorsqu&rsquo;ils g\u00e8rent plusieurs syst\u00e8mes et utilisateurs. Un besoin courant est d&rsquo;envoyer des notifications ou des rappels aux utilisateurs concernant les mises \u00e0 jour du syst\u00e8me, la maintenance ou d&rsquo;autres actions critiques. Cet article se penche sur un script Bash polyvalent con\u00e7u pour <strong>cr\u00e9er des pop-up (messages contextuels) sur les syst\u00e8mes Linux<\/strong>, un outil utile pour les administrateurs informatiques 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>.<\/p>\n<h2>Contexte<\/h2>\n<p>Dans le monde dynamique de l&rsquo;informatique, une communication opportune peut pr\u00e9venir la perte de donn\u00e9es et garantir que les utilisateurs sont bien inform\u00e9s des activit\u00e9s du syst\u00e8me. Le script Bash dont nous parlons aujourd&rsquo;hui est con\u00e7u pour les environnements Linux et est compatible avec les bureaux X11 KDE et X11 Gnome. Ce script n&rsquo;envoie pas seulement des messages \u00e0 tous les terminaux connect\u00e9s, mais cr\u00e9e \u00e9galement une fen\u00eatre contextuelle sur l&rsquo;\u00e9cran de l&rsquo;utilisateur, ce qui garantit que les notifications importantes sont vues rapidement.<\/p>\n<h2>Le script\u00a0:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/usr\/bin\/env bash\r\n#\r\n# Description: Outputs messages on all connected terminals and creates a popup window on the end-user's screen. The popup requires ImageMagick and supports X11 KDE &amp; X11 Gnome environments; other environments will only display the terminal message. Use the \"Restart Reminder\" feature to trigger a generic restart prompt.\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: --restartreminder\r\n#   Displays a generic restart PopUp. Can be overridden with parameters. Equivalent to the below parameters.\r\n#   --title 'NinjaOne Rmm'\r\n#   --message 'Your IT Administrator has scheduled a restart of your computer in the next 15 minutes. Please save your work as soon as possible to prevent data loss.'\r\n#   --timeoutaction 'shutdown -r'\r\n#\r\n# Preset Parameter: --title 'ReplaceWithYourDesiredHeader'\r\n#   Replace the text encased in quotes to replace the text in the title bar of the popup window (defaults to 'NinjaOne RMM').\r\n#\r\n# Preset Parameter: --message 'ReplaceWithYourPopUpMessage'\r\n#   Replace the text encased in quotes to put some text inside of the PopUp Window.\r\n#\r\n# Preset Parameter: --iconpath 'A URL or \/a\/path\/to\/an\/image.png'\r\n#   Replace the text encased in quotes with either a url to an image or a filepath to an icon. The script uses the NinjaOne Logo by default.\r\n#   For best results use a 128px x 128px png. Though other formats and sizes will work.\r\n#   Highly recommend keeping a 1:1 ratio for the width and height.\r\n#   Supported formats: png, jpg, jpeg, webp, bmp, ico and gif (will not be animated in popup)\r\n#   If you have a base64 encoding of your image you could also replace the default base64 on line 37.\r\n#\r\n# Preset Parameter: --timeout 'ReplaceWithAnumberofSeconds'\r\n#   Replace the text encased in quotes with the number of seconds you'd like the PopUp to display for.\r\n#\r\n# Preset Parameter: --okbuttonaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\r\n#   Replace the text encased in quotes with the command you'd like to run when the left button is clicked by the user (executes in bash).\r\n#\r\n# Preset Parameter: --exitbuttonaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\r\n#   Replace the text encased in quotes with the command you'd like to run when the popup window is closed (executes in bash).\r\n#\r\n# Preset Parameter: --timeoutaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\r\n#   Replace the text encased in quotes with the command you'd like to run when the dialog box times out (executes in bash).\r\n\r\n# You can replace the below line with iconbase64='ReplaceThisWithYourBase64encodedimageEncasedInQuotes' and the script will decode the image and use it in the popup window.\r\niconbase64='iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAJFBMVEUARF0Apc0AmL8ApM0Aos0Aps7\/\/\/8Am8ia1ug9rtLd8\/jw+\/2tMDHwAAAABXRSTlMBrBTIcce4nvwAAAIeSURBVHic7dvrcoMgEAXgiOAivv\/7Fm+JBpCLwk7bsz86rcNkPw+Y0Gl5vd4lGtbLKSG7vmF18mwQnWpe3YcghP2Z1svU8OtbIOihm8op25M2gWBov9UqYJj\/vSRzAGsEkhMglxngWINbdbxLAAAAAAAAAAAAAKAI8Oz2KRtApPWThEyAbT8NZwDZGpeav6sLIKXNMBwAtuGotTGTvTpMRms9qkxEBsDe\/dz+A7B3rufeS\/utrCKPkAywzfYmK8BeOHY+lBkzBImALfwDgA4XnNLphCTA4e43AKmL9vNMJD8pCQAna20nP5D+SfkQgJyp1qS9PYsEKQDnpVP627WYJCgBmGj+GRmUAFIraSXWBAwDcwJJk1AXMIzcgHgElQHxCGoDohHcBsybgIvPpei70S2A0csuaNkTBRBTbA7uAOb271E0+gWxOSgHfG87yD+wGsCz7fGONNf9iwGTb89DnlkwkUVQCPD2t1sXz9A6gMDT5YsgsggKARljI\/vTMkDo7cU3B1USCL+oOwdVAMGF5RlcAxB+tBoBwq\/JDlDcAPYEAGgDuPiNBwkgASSABJAAEkACSAAJIAEkgASQABL4JwlcA9w\/9N4GTOZcl1OQMTgRoEannhv9O\/+PCAAAAAAAAAAAAACAPwhgP+7HeOCR1jOfjBHI9dBrz9W\/34\/d9jyHLvvPweP2GdCx\/3zyvLlAfZ8+l13LktJzAJ+nfgAP50EVLvPsRgAAAABJRU5ErkJggg=='\r\nworkingdir=\"\/tmp\/ninjaone-rmm-popup\"\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\n# THE DEFAULTS INITIALIZATION - OPTIONALS\r\n_arg_title=\"NinjaOne RMM\"\r\n_arg_message=\r\n_arg_iconpath=\r\n_arg_obuttonaction=\r\n_arg_ebuttonaction=\r\n_arg_timeoutaction=\r\n_arg_timeout=900\r\n_arg_restartreminder=\"off\"\r\n\r\n# The function will print out some help text if the user entered in something wrong\r\nprint_help() {\r\n    printf '\\t%s\\n\\n' 'Usage: [-t|--title &lt;arg&gt;] [-m|-msg|--message &lt;arg&gt;] [-i|-icon|--iconpath &lt;arg&gt;] [-ea | -ebtnact | -extbtnaction | --exitbuttonaction &lt;arg&gt;] [-oa | -okbtnact | -okbtnaction | --okbuttonaction &lt;arg&gt;] [-to | --timeout &lt;arg&gt;] [-toa | -toact| --timeoutaction &lt;arg&gt;] [ -restart | --restartreminder] [-h|--help]'\r\n    printf '%s\\n' \"Preset Parameter: --restartreminder\"\r\n    printf '\\t%s\\n' \"Displays a generic restart PopUp. Can be overridden with parameters. Equivelant to the below parameters.\"\r\n    printf '\\t%s\\n' \"--title 'NinjaOne Rmm'\"\r\n    printf '\\t%s\\n' \"--message 'Your IT Administrator has scheduled a restart of your computer in the next 15 minutes. Please save your work as soon as possible to prevent data loss.'\"\r\n    printf '\\t%s\\n' \"--timeoutaction 'shutdown -r'\"\r\n    printf '%s\\n' \"Preset Parameter: --title 'ReplaceWithYourDesiredHeader'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes to replace the text in the title bar of the popup window (defaults to 'NinjaOne RMM')\"\r\n    printf '%s\\n' \"Preset Parameter: --message 'ReplaceWithYourPopUpMessage'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes to put some text inside of the PopUp Window\"\r\n    printf '%s\\n' \"Preset Parameter: --iconpath 'A URL or \/a\/path\/to\/an\/image.png'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes with either a url to an image or a filepath to an icon. The script uses the NinjaOne Logo by default.\"\r\n    printf '%s\\n' \"Preset Parameter: --timeout 'ReplaceWithAnumberofSeconds'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes with the number of seconds you'd like the PopUp to display for.\"\r\n    printf '%s\\n' \"Preset Parameter: --okbuttonaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes with the command you'd like to run when the ok button is clicked by the user (executes in bash).\"\r\n    printf '%s\\n' \"Preset Parameter: --exitbuttonaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes with the command you'd like to run when the user closes the dialog (executes in bash).\"\r\n    printf '%s\\n' \"Preset Parameter: --timeoutaction 'ReplaceWithYourDesiredAction(Executes in Bash)'\"\r\n    printf '\\t%s\\n' \"Replace the text encased in quotes with the command you'd like to run when the dialog box times out (executes in bash).\"\r\n}\r\n\r\n# decipher's the parameters given and stores them as variables\r\nparse_commandline() {\r\n    while test $# -gt 0; do\r\n        _key=\"$1\"\r\n        case \"$_key\" in\r\n        -t | --title)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_title=\"$2\"\r\n            shift\r\n            ;;\r\n        --title=*)\r\n            _arg_title=\"${_key##--title=}\"\r\n            ;;\r\n        -m | -msg | --message)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_message=\"$2\"\r\n            shift\r\n            ;;\r\n        --message=*)\r\n            _arg_message=\"${_key##--message=}\"\r\n            ;;\r\n        --msg=*)\r\n            _arg_message=\"${_key##--msg=}\"\r\n            ;;\r\n        -i | -icon | --iconpath)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_iconpath=\"$2\"\r\n            shift\r\n            ;;\r\n        --iconpath=*)\r\n            _arg_iconpath=\"${_key##--iconpath=}\"\r\n            ;;\r\n        --icon=*)\r\n            _arg_iconpath=\"${_key##--icon=}\"\r\n            ;;\r\n        -ea | -ebtnact | -extbtnaction | --exitbuttonaction)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_ebuttonaction=\"$2\"\r\n            shift\r\n            ;;\r\n        --exitbuttonaction=*)\r\n            _arg_ebuttonaction=\"${_key##--ebuttonaction=}\"\r\n            ;;\r\n        -oa | -okbtnact | -okbtnaction | --okbuttonaction)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_obuttonaction=\"$2\"\r\n            shift\r\n            ;;\r\n        --okbuttonaction=*)\r\n            _arg_obuttonaction=\"${_key##--obuttonaction=}\"\r\n            ;;\r\n        -to | --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        -toa | -toact | --timeoutaction)\r\n            test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n            _arg_timeoutaction=\"$2\"\r\n            shift\r\n            ;;\r\n        --timeoutaction=*)\r\n            _arg_timeoutaction=\"${_key##--timeoutaction=}\"\r\n            ;;\r\n        -restart | --restartreminder)\r\n            _arg_restartreminder=\"on\"\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\n# Initializes parameter processing\r\nparse_commandline \"$@\"\r\n\r\nif [[ -n $title ]]; then\r\n    _arg_title=$title\r\nfi\r\n\r\nif [[ -n $message ]]; then\r\n    _arg_message=$message\r\nfi\r\n\r\nif [[ -n $iconPath ]]; then\r\n    _arg_iconpath=$iconPath\r\nfi\r\n\r\nif [[ -n $timeout ]]; then\r\n    _arg_timeout=$timeout\r\nfi\r\n\r\nif [[ -n $timeoutAction ]]; then\r\n    _arg_timeoutaction=$timeoutAction\r\nfi\r\n\r\nif [[ -n $okButtonAction ]]; then\r\n    _arg_obuttonaction=$okButtonAction\r\nfi\r\n\r\nif [[ -n $exitButtonAction ]]; then\r\n    _arg_ebuttonaction=$exitButtonAction\r\nfi\r\n\r\nif [[ -n $restartReminder &amp;&amp; $restartReminder == \"true\" ]]; then\r\n    _arg_restartreminder=\"on\"\r\nfi\r\n\r\n# If --restartreminder was selected we'll want to preset some of the parameters\r\nif [[ $_arg_restartreminder == \"on\" ]]; then\r\n    if [[ -z $_arg_message ]]; then\r\n        _arg_message=\"Your IT Administrator has scheduled a restart of your computer in the next 15 minutes. Please save your work as soon as possible to prevent data loss.\"\r\n    fi\r\n\r\n    if [[ -z $_arg_timeoutaction ]]; then\r\n        _arg_timeoutaction='shutdown -r'\r\n    fi\r\nfi\r\n\r\n# Grabbing information about the current setup\r\nactiveUsers=$(loginctl list-sessions | grep seat | sed 's\/[0-9]\\+\/\/g' | sed 's\/seat\/\/g' | sed 's\/tty\/\/g' | xargs)\r\nactiveDisplay=$(w -oush | grep -Eo ' :[0-9]+' | uniq | head -1 | xargs)\r\nGNOME=$(command -v zenity)\r\nKDE=$(command -v kdialog)\r\nimageMagick=$(command -v convert)\r\n\r\n# Must give a number\r\npattern='^[0-9]+$'\r\nif [[ ! $_arg_timeout =~ $pattern ]]; then\r\n    _PRINT_HELP=no die \"FATAL ERROR: --timeout requires a number of seconds in order to work. ex. '60' for 60 seconds.\" 1\r\nfi\r\n\r\n# No matter what we're going to send a message to all connected terminals\r\necho \"Sending message to all connected terminals.\"\r\nwall \"$_arg_message\"\r\nif [[ -z $imageMagick ]]; then\r\n    echo \"WARNING: Image Magick is not installed. This script will be unable to display a popup without it. This script will still be able to send a message to all ssh connected terminals.\"\r\nfi\r\n\r\n# If not on a supported desktop environment or simply nobodies logged in skip this whole block.\r\nif [[ (-n $GNOME || -n $KDE) &amp;&amp; -n $activeDisplay &amp;&amp; -n $activeUsers &amp;&amp; -n $imageMagick ]]; then\r\n    # Create's a working directory if it doesn't already exist\r\n    if [[ ! -d \"$workingdir\" ]]; then\r\n        mkdir $workingdir\r\n    fi\r\n\r\n    # If given a url attempt to download the image file\r\n    pattern=\"https?:\/\/.*\"\r\n    if [[ $_arg_iconpath =~ $pattern ]]; then\r\n        wget -q \"$_arg_iconpath\" -O \"$workingdir\/downloadedimg\" -t 7 --random-wait\r\n        _arg_iconpath=$workingdir\/downloadedimg\r\n    fi\r\n\r\n    # If a base64 icon is provided and no other iconpath was specified use that.\r\n    if [[ -n $iconbase64 &amp;&amp; -z $_arg_iconpath ]]; then\r\n        base64 -d &lt;&lt;&lt;$iconbase64 &gt;$workingdir\/base64img\r\n        _arg_iconpath=$workingdir\/base64img\r\n    # If an iconpath was provided copy it to the working directory\r\n    elif [[ ! $_arg_iconpath == \"$workingdir\/downloadedimg\" ]]; then\r\n        cp \"$_arg_iconpath\" \"$workingdir\/downloadedimg\"\r\n        _arg_iconpath=\"$workingdir\/downloadedimg\"\r\n    fi\r\n\r\n    # Dobule check that we were given an image and find it's extension\r\n    mimetype=$(file --mime-type -b \"$_arg_iconpath\" | grep \"image\")\r\n    extension=$(file --extension -b \"$_arg_iconpath\" | sed 's\/\\\/.*\/\/g')\r\n\r\n    # If the mimetype indicates its not an image error out\r\n    if [[ -z $mimetype ]]; then\r\n        _PRINT_HELP=no die \"FATAL ERROR: No image found!\" 1\r\n    # If it's not a png we'll need to convert it to one and it'll need to be 128x128.\r\n    elif [[ ! $extension == \"png\" ]]; then\r\n        cp \"$_arg_iconpath\" \"$workingdir\/img.$extension\"\r\n        convert -resize 128x128! -background none -coalesce \"$workingdir\/img.$extension\" \"$workingdir\/img.png\"\r\n        # Some image types ex. .ico files will have multiple pngs embeded in it. This ensures only one is selected.\r\n        _arg_iconpath=$(find $workingdir\/img*.png | tail -1)\r\n    fi\r\n\r\n    # If post conversion we don't have an image we can use error out\r\n    if [[ -n $_arg_iconpath ]]; then\r\n        mv \"$_arg_iconpath\" \"$workingdir\/$_arg_title.png\"\r\n        convert \"$workingdir\/$_arg_title.png\" -resize 128x128! \"\/usr\/share\/pixmaps\/$_arg_title.png\"\r\n        _arg_iconpath=\"\/usr\/share\/pixmaps\/$_arg_title.png\"\r\n    else\r\n        _PRINT_HELP=no die \"FATAL ERROR: Image missing after converting to png?\" 1\r\n    fi\r\n\r\n    # If using the Gnome Desktop enviornment we'll need to use zenity otherwise we can use kdialog.\r\n    if [[ -n $GNOME ]]; then\r\n        export DISPLAY=\"$activeDisplay\"\r\n        for user in $activeUsers; do\r\n            popup=$(\r\n                $popup\r\n                su \"$user\" -c 'xhost local:'\"$user\"'; zenity --window-icon \"'\"$_arg_iconpath\"'\" --title \"'\"$_arg_title\"'\" --icon-name \"'\"$_arg_title\"'\" --info --text \"'\"$_arg_message\"'\" --timeout \"'\"$_arg_timeout\"'\"'\r\n                echo -e \"\\n$?\"\r\n            )\r\n        done\r\n    elif [[ -n $KDE ]]; then\r\n        export DISPLAY=\"$activeDisplay\"\r\n        for user in $activeUsers; do\r\n            popup=$(\r\n                $popup\r\n                # kdialog doesn't seem to have an option for an actual dialog to time out so we'll make a popup message instead\r\n                su \"$user\" -c 'xhost local:'\"$user\"'; kdialog --icon \"'\"$_arg_iconpath\"'\" --title \"'\"$_arg_title\"'\" --passivepopup \"'\"$_arg_message\"'\" '\"$_arg_timeout\"''\r\n                echo -e \"\\n$?\"\r\n            )\r\n        done\r\n    fi\r\n\r\n    # This grabs the exitcode for each time the dialog was ran\r\n    results=$(echo \"$popup\" | grep -Eo '[0-9]')\r\n    for result in $results; do\r\n        if [[ $result == -1 || $result == 254 ]]; then\r\n            _PRINT_HELP=no die \"FATAL ERROR: Unable to display popup?\" 1\r\n        fi\r\n\r\n        # Kdialog will give an exit code of 2 when exiting while Gnome will give an exit code of 1\r\n        if [[ -n $_arg_ebuttonaction &amp;&amp; ($result == 1 || $result == 2) ]]; then\r\n            echo \"Exit Button Clicked\"\r\n            eval \"$_arg_ebuttonaction\"\r\n        elif [[ $result == 1 || $result == 2 ]]; then\r\n            echo \"Exit Button Clicked\"\r\n        fi\r\n\r\n        if [[ -n $_arg_obuttonaction &amp;&amp; $result == 0 &amp;&amp; -n $GNOME ]]; then\r\n            echo \"OK Button Clicked\"\r\n            eval \"$_arg_obuttonaction\"\r\n        elif [[ $result == 0 &amp;&amp; -n $GNOME ]]; then\r\n            echo \"OK Button Clicked\"\r\n        fi\r\n\r\n        if [[ -n $_arg_timeoutaction &amp;&amp; $result == 5 || (-n $KDE &amp;&amp; $result == 0) ]]; then\r\n            echo \"Pop-up has timed out! Executing timeout action....\"\r\n            eval \"$_arg_timeoutaction\"\r\n        elif [[ $result == 5 || (-n $KDE &amp;&amp; $result == 0) ]]; then\r\n            echo \"Pop-up has timed out!\"\r\n        fi\r\n    done\r\n\r\n    # Removes the old icon\r\n    rm \"$_arg_iconpath\"\r\nelse\r\n    echo \"No active X11 displays using GNOME or KDE were found. This script will display a terminal message only.\"\r\n    if [[ ! $_arg_timeout == 0 ]]; then\r\n        echo \"Sleeping for $_arg_timeout seconds...\"\r\n        sleep \"$_arg_timeout\"\r\n    fi\r\n    if [[ -n $_arg_timeoutaction ]]; then\r\n        echo \"Executing timeout action.\"\r\n        eval \"$_arg_timeoutaction\"\r\n    fi\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 a \u00e9t\u00e9 con\u00e7u dans un souci de flexibilit\u00e9, offrant divers param\u00e8tres pour personnaliser les messages pop-up. Voici une description d\u00e9taill\u00e9e de son fonctionnement :<\/p>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Initialisation et fonction d&rsquo;aide<\/strong>: Le script commence par d\u00e9finir des valeurs par d\u00e9faut pour divers param\u00e8tres, tels que le titre, le message, le chemin d&rsquo;acc\u00e8s \u00e0 l&rsquo;ic\u00f4ne, la dur\u00e9e du d\u00e9lai d&rsquo;attente et les actions pour les boutons OK et Quitter. Il comprend \u00e9galement une fonction d&rsquo;aide pour guider les utilisateurs sur la mani\u00e8re d&rsquo;utiliser efficacement le script.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Analyse des param\u00e8tres<\/strong>: La fonction parse_commandline traite les arguments d&rsquo;entr\u00e9e, permettant aux utilisateurs d&rsquo;ignorer les valeurs par d\u00e9faut. Les param\u00e8tres comprennent &#8211;title, &#8211;message, &#8211;iconpath, &#8211;timeout, &#8211;okbuttonaction, &#8211;exitbuttonaction et &#8211;timeoutaction.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Configuration de l&rsquo;environnement<\/strong>: Le script v\u00e9rifie la configuration actuelle pour d\u00e9terminer les utilisateurs actifs et les environnements d&rsquo;affichage. Il prend en charge les bureaux Gnome et KDE, et s&rsquo;appuie sur des outils tels que zenity et kdialog pour cr\u00e9er des messages contextuels.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Traitement des ic\u00f4nes<\/strong>: Si une URL d&rsquo;ic\u00f4ne est fournie, le script t\u00e9l\u00e9charge l&rsquo;image. Il prend \u00e9galement en charge les images cod\u00e9es en base64, qui peuvent \u00eatre d\u00e9cod\u00e9es et utilis\u00e9es dans la fen\u00eatre contextuelle. Le script s&rsquo;assure que l&rsquo;image est au format PNG et la redimensionne \u00e0 128&#215;128 pixels si n\u00e9cessaire.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Cr\u00e9ation de la fen\u00eatre contextuelle<\/strong>: En fonction de l&rsquo;environnement de bureau, le script utilise zenity ou kdialog pour afficher le message contextuel. Il g\u00e8re diverses actions bas\u00e9es sur les interactions de l&rsquo;utilisateur, comme le fait de cliquer sur les boutons OK ou Quitter ou lorsque la fen\u00eatre contextuelle se termine.<\/li>\n<li data-leveltext=\"%1.\" data-font=\"Aptos\" data-listid=\"1\" 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=\"1\" data-aria-level=\"1\"><strong>Repli pour les messages du terminal<\/strong>: Si aucun environnement de bureau ad\u00e9quat n&rsquo;est trouv\u00e9, le script se contente d&rsquo;envoyer des messages \u00e0 tous les terminaux connect\u00e9s, ce qui garantit que la notification est toujours communiqu\u00e9e.<\/li>\n<\/ol>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<p>Imaginez un professionnel de l&rsquo;informatique qui g\u00e8re un r\u00e9seau d&rsquo;ordinateurs dans un environnement d&rsquo;entreprise. Il est urgent de red\u00e9marrer plusieurs machines en raison d&rsquo;une mise \u00e0 jour critique. Gr\u00e2ce \u00e0 ce script, l&rsquo;administrateur informatique peut envoyer un message contextuel \u00e0 tous les utilisateurs, les informant du red\u00e9marrage imminent et les invitant \u00e0 sauvegarder leur travail. Les utilisateurs sont ainsi inform\u00e9s de l&rsquo;action et peuvent se pr\u00e9parer en cons\u00e9quence, ce qui minimise les perturbations et les pertes de donn\u00e9es.<\/p>\n<h2>Comparaisons<\/h2>\n<p>D&rsquo;autres m\u00e9thodes pour informer les utilisateurs sont les alertes par courrier \u00e9lectronique, les messages de chat ou m\u00eame les appels t\u00e9l\u00e9phoniques. Toutefois, ces m\u00e9thodes peuvent ne pas \u00eatre aussi imm\u00e9diates ou perceptibles qu&rsquo;un message contextuel directement sur l&rsquo;\u00e9cran de l&rsquo;utilisateur. Ce script offre une m\u00e9thode de notification directe et incontournable, garantissant que les messages importants sont vus rapidement.<\/p>\n<h2>FAQ<\/h2>\n<h3>1) Comment puis-je personnaliser le message contextuel ?<\/h3>\n<p>Vous pouvez personnaliser le message en utilisant le param\u00e8tre &#8211;message suivi du texte souhait\u00e9.<\/p>\n<h3>2) Puis-je utiliser une image dans la fen\u00eatre contextuelle ?<\/h3>\n<p>Oui, vous pouvez sp\u00e9cifier une URL d&rsquo;image ou un chemin de fichier en utilisant le param\u00e8tre &#8211;iconpath.<\/p>\n<h3>3) Que se passe-t-il si le script s&rsquo;ex\u00e9cute sur un syst\u00e8me sans GNOME ou KDE ?<\/h3>\n<p>Le script continuera \u00e0 envoyer des messages \u00e0 tous les terminaux connect\u00e9s, mais ne cr\u00e9era pas de fen\u00eatre contextuelle.<\/p>\n<h3>4) Comment puis-je d\u00e9finir la dur\u00e9e d&rsquo;affichage de la fen\u00eatre contextuelle ?<\/h3>\n<p>Utilisez le param\u00e8tre &#8211;timeout suivi du nombre de secondes pendant lesquelles vous souhaitez que la fen\u00eatre contextuelle s&rsquo;affiche.<\/p>\n<h3>5) Est-il possible d&rsquo;ex\u00e9cuter une commande lorsque la fen\u00eatre contextuelle s&rsquo;\u00e9teint ?<\/h3>\n<p>Oui, vous pouvez sp\u00e9cifier une commande \u00e0 ex\u00e9cuter en cas de d\u00e9passement de d\u00e9lai \u00e0 l&rsquo;aide du param\u00e8tre &#8211;timeoutaction.<\/p>\n<h2>Implications<\/h2>\n<p>L&rsquo;utilisation de ce script renforce la s\u00e9curit\u00e9 informatique en garantissant que les notifications critiques ne sont pas manqu\u00e9es. Qu&rsquo;il s&rsquo;agisse d&rsquo;un red\u00e9marrage du syst\u00e8me, d&rsquo;un rappel de maintenance ou d&rsquo;une alerte de s\u00e9curit\u00e9, le script garantit que les utilisateurs sont rapidement inform\u00e9s, ce qui r\u00e9duit le risque de perte de donn\u00e9es et garantit l&rsquo;int\u00e9grit\u00e9 du syst\u00e8me.<\/p>\n<h2>Recommandations<\/h2>\n<p>Lors de l&rsquo;utilisation de ce script, il est important de :<\/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=\"1\" data-aria-level=\"1\">Testez le script dans un environnement contr\u00f4l\u00e9 avant de le d\u00e9ployer \u00e0 grande \u00e9chelle.<\/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=\"2\" data-aria-level=\"1\">Veillez \u00e0 ce que ImageMagick soit install\u00e9 pour pouvoir g\u00e9rer les images.<\/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\">Personnalisez les param\u00e8tres pour r\u00e9pondre aux besoins sp\u00e9cifiques de votre organisation.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Des outils de communication efficaces sont essentiels pour la gestion des technologies de l&rsquo;information. Ce script Bash offre un moyen fiable d&rsquo;envoyer des messages contextuels aux utilisateurs de Linux, garantissant que les notifications critiques sont vues et prises en compte. Pour les professionnels de l&rsquo;informatique et les MSP, ces outils sont inestimables pour maintenir l&rsquo;int\u00e9grit\u00e9 du syst\u00e8me et assurer la conformit\u00e9 des utilisateurs avec les mises \u00e0 jour et les actions importantes.<\/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":[4211],"use_cases":[4281],"class_list":["post-353654","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux","use_cases-configuration-generale"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/353654","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=353654"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=353654"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=353654"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=353654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}