{"id":353790,"date":"2024-09-17T12:54:03","date_gmt":"2024-09-17T12:54:03","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/crear-pop-ups\/"},"modified":"2024-10-13T19:08:27","modified_gmt":"2024-10-13T19:08:27","slug":"crear-pop-ups","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/es\/script-hub\/crear-pop-ups\/","title":{"rendered":"C\u00f3mo crear pop-ups eficaces en Linux para profesionales de TI y MSP"},"content":{"rendered":"<p>Una comunicaci\u00f3n eficaz es vital para los profesionales de TI, sobre todo cuando gestionan m\u00faltiples sistemas y usuarios. Una necesidad com\u00fan es enviar notificaciones o recordatorios a los usuarios sobre actualizaciones del sistema, mantenimiento u otras acciones cr\u00edticas. Este post profundiza en un vers\u00e1til script de Bash dise\u00f1ado <strong>para crear pop-ups en sistemas Linux<\/strong>, una herramienta \u00fatil para administradores de TI y <a href=\"https:\/\/www.ninjaone.com\/es\/que-es-un-msp\" target=\"_blank\" rel=\"noopener\">proveedores de servicios gestionados (MSP)<\/a>.<\/p>\n<h2>Contexto<\/h2>\n<p>En el din\u00e1mico mundo de las TI, una comunicaci\u00f3n a tiempo puede evitar la p\u00e9rdida de datos y garantizar que los usuarios est\u00e9n bien informados sobre las actividades del sistema. El script Bash que vamos a comentar hoy est\u00e1 adaptado a entornos Linux y es compatible con los escritorios X11 KDE y X11 Gnome. Este script no s\u00f3lo env\u00eda mensajes a todos los terminales conectados, sino que tambi\u00e9n crea una ventana emergente visual en la pantalla del usuario, lo que garantiza que las notificaciones importantes se vean con prontitud.<\/p>\n<h2>El script para <strong>crear pop-ups en sistemas Linux<\/strong><\/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=\"blog-cta-new blog-cta-style-1\"><div class=\"cta-left\"><h2><\/h2><p><\/p><\/div><div class=\"cta-right\"><a class=\"button\" href=\"\"><\/a><\/div><\/div>\n<h2>An\u00e1lisis detallado<\/h2>\n<p>El script est\u00e1 dise\u00f1ado con la flexibilidad en mente, ofreciendo varios par\u00e1metros para personalizar los mensajes emergentes. Aqu\u00ed tienes un desglose paso a paso de c\u00f3mo funciona:<\/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>Inicializaci\u00f3n y funci\u00f3n de ayuda<\/strong>: el script comienza definiendo valores por defecto para varios par\u00e1metros, como el t\u00edtulo, el mensaje, la ruta del icono, la duraci\u00f3n del tiempo de espera y las acciones para los botones Aceptar y Salir. Tambi\u00e9n incluye una funci\u00f3n de ayuda para orientar a los usuarios sobre c\u00f3mo utilizar el script de forma eficaz.<\/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>An\u00e1lisis de par\u00e1metros<\/strong>: la funci\u00f3n parse_commandline procesa los argumentos de entrada, permitiendo a los usuarios anular los valores por defecto. Los par\u00e1metros son &#8211;title, &#8211;message, &#8211;iconpath, &#8211;timeout, &#8211;okbuttonaction, &#8211;exitbuttonaction y &#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>Configuraci\u00f3n del entorno<\/strong>: el script comprueba la configuraci\u00f3n actual para determinar los usuarios activos y los entornos de visualizaci\u00f3n. Es compatible con los escritorios Gnome y KDE, y aprovecha herramientas como zenity y kdialog para crear pop-ups.<\/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>Gesti\u00f3n de los iconos<\/strong>: si se proporciona una URL de icono, el script descarga la imagen. Tambi\u00e9n admite im\u00e1genes codificadas en base64, que pueden descodificarse y utilizarse en la ventana emergente. El script se asegura de que la imagen est\u00e1 en formato PNG y la redimensiona a 128&#215;128 p\u00edxeles si es necesario.<\/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>Creaci\u00f3n de la ventana emergente<\/strong>: dependiendo del entorno de escritorio, el script utiliza zenity o kdialog para mostrar el mensaje emergente. Gestiona varias acciones basadas en las interacciones del usuario, como hacer clic en los botones Aceptar o Salir o cuando se agota el tiempo de espera de la ventana emergente.<\/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>Fallback para mensajes de terminal<\/strong>: si no se encuentra un entorno de escritorio adecuado, el script vuelve a enviar mensajes a todos los terminales conectados, asegur\u00e1ndose de que se sigue comunicando la notificaci\u00f3n.<\/li>\n<\/ol>\n<h2>Posibles casos de uso<\/h2>\n<p>Imagina a un profesional de TI que gestiona una red de ordenadores en un entorno corporativo. Hay una necesidad urgente de reiniciar varias m\u00e1quinas debido a una actualizaci\u00f3n cr\u00edtica. Con este script, el administrador de TI puede enviar un mensaje emergente a todos los usuarios, inform\u00e1ndoles del inminente reinicio e inst\u00e1ndoles a guardar su trabajo. Esto garantiza que los usuarios est\u00e9n al tanto de la acci\u00f3n y puedan prepararse en consecuencia, minimizando las interrupciones y la p\u00e9rdida de datos.<\/p>\n<h2>Comparaciones<\/h2>\n<p>Otros m\u00e9todos para notificar a los usuarios son las alertas por correo electr\u00f3nico, los mensajes de chat o incluso las llamadas telef\u00f3nicas. Sin embargo, estos m\u00e9todos pueden no ser tan inmediatos o perceptibles como un mensaje emergente directamente en la pantalla del usuario. Este script ofrece un m\u00e9todo de notificaci\u00f3n directo e ineludible, garantizando que los mensajes importantes se vean con prontitud.<\/p>\n<h2>FAQ<\/h2>\n<h3>1) \u00bfC\u00f3mo personalizo el mensaje emergente?<\/h3>\n<p>Puedes personalizar el mensaje utilizando el par\u00e1metro &#8211;message seguido del texto que quieras.<\/p>\n<h3>2) \u00bfPuedo utilizar una imagen en la ventana emergente?<\/h3>\n<p>S\u00ed, puedes especificar una URL de imagen o una ruta de archivo utilizando el par\u00e1metro &#8211;iconpath.<\/p>\n<h3>3) \u00bfQu\u00e9 ocurre si el script se ejecuta en un sistema sin GNOME o KDE?<\/h3>\n<p>El script seguir\u00e1 enviando mensajes a todos los terminales conectados, pero no crear\u00e1 una ventana emergente.<\/p>\n<h3>4) \u00bfC\u00f3mo establezco la duraci\u00f3n de la ventana emergente?<\/h3>\n<p>Utiliza el par\u00e1metro &#8211;timeout seguido del n\u00famero de segundos que deseas que aparezca la ventana emergente.<\/p>\n<h3>5) \u00bfEs posible ejecutar un comando cuando se agota el tiempo de espera de la ventana emergente?<\/h3>\n<p>S\u00ed, puedes especificar un comando para que se ejecute cuando se agote el tiempo de espera utilizando el par\u00e1metro &#8211;timeoutaction.<\/p>\n<h2>Implicaciones<\/h2>\n<p>El uso de este script mejora la seguridad inform\u00e1tica al garantizar que no se pierdan las notificaciones cr\u00edticas. Ya se trate de un reinicio del sistema, un recordatorio de mantenimiento o una alerta de seguridad, el script garantiza que los usuarios est\u00e9n puntualmente informados, reduciendo el riesgo de p\u00e9rdida de datos y asegurando la integridad del sistema.<\/p>\n<h2>Recomendaciones<\/h2>\n<p>Al utilizar este script, es importante:<\/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\">Probar el script en un entorno controlado antes de desplegarlo ampliamente.<\/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\">Asegurarte de que ImageMagick est\u00e1 instalado para la gesti\u00f3n de im\u00e1genes.<\/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\">Personalizar los par\u00e1metros para adaptarlos a las necesidades espec\u00edficas de la organizaci\u00f3n.<\/li>\n<\/ul>\n<h2>Reflexiones finales<\/h2>\n<p>Unas herramientas de comunicaci\u00f3n eficaces son esenciales para la gesti\u00f3n de las TI. Este script de Bash proporciona una forma fiable de enviar mensajes emergentes a los usuarios de Linux, garantizando que las notificaciones cr\u00edticas se vean y se act\u00fae en consecuencia. Para los profesionales de TI y los MSP, este tipo de herramientas tienen un valor incalculable a la hora de mantener la integridad del sistema y garantizar el cumplimiento por parte de los usuarios de las actualizaciones y acciones 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":[4259],"class_list":["post-353790","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub\/353790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/comments?post=353790"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media?parent=353790"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/operating_system?post=353790"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/use_cases?post=353790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}