Linux: User Notifications

How to set up user notifications for Linux devices

Notifications for Linux devices can be achieved using the following methodology that takes advantage of libraries and packages built into many Linux distributions. The following solution involving Shell/BASH code in a Worklet Policy can be implemented as part of custom Worklet code.

  1. To create a custom Worklet Policy, go to Manage > Policies.
  2. Click Create Policy.

    manage-policies-createpolicy.png

  3. From the Worklet section, select Linux.
  4. Assign a name to the Worklet Policy, then associate the appropriate Group(s) and/or use Device Targeting.
  5. Under Scope, copy and paste the code below into the appropriate blocks. Adjust as needed.


    EVALUATION code

    A simple 'exit 1' will suffice to ensure that the Remediation code will execute every time this Policy runs:

    #!/bin/bash
    exit 1

    REMEDIATION code

    #!/bin/bash

    #================================================================
    # HEADER
    #================================================================
    #% SYNOPSIS
    #+ Sends a notification to a Linux desktop
    #%
    #% DESCRIPTION
    #% Sends a notification to a Linux desktop
    #%
    #% USAGE
    #% ./remediation.sh
    #%
    #% EXAMPLES
    #% ./remediation.sh
    #%
    #================================================================
    #- IMPLEMENTATION
    #- version (www.automox.com) 1.0
    #- author Elmer Pallarca
    #-
    #================================================================
    # HISTORY
    # 05/23/2022 : Elmer Pallarca : Script creation
    # ##/##/#### : ####: Validated and catalogued
    #
    #================================================================
    # END_OF_HEADER
    #================================================================

    ## Start Configurable Items
    title='Message from Automox'
    message_text='Updates require reboot: Please save your work.'
    width=400
    height=100
    timeout_duration=60 # in seconds
    ## End Configurable Items

    # Send the Notification to user sessions
    wall -n "$message_text"

    # Create the GTK+ Dialog box via Zenity for all logged in users
    who | awk '{print $1}' | sort | uniq | (read user; sudo -u $user \
    DISPLAY=:0 \
    zenity --warning --title=$title --text "$message_text" \
    --width $width --height $height --timeout=$timeout_duration)

    exit
  6. Under the Schedule section, configure the scheduling of the Worklet Policy as per usual.
  7. Click Create Policy.

This functionality can be also combined with existing Worklet code that can 1) apply required patches/updates, and 2) possibly reboot the device(s) afterwards (if needed).

Was this article helpful?
0 out of 0 found this helpful