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.
- To create a custom Worklet Policy, go to Manage > Policies.
- Click Create Policy.
- From the Worklet section, select Linux.
- Assign a name to the Worklet Policy, then associate the appropriate Group(s) and/or use Device Targeting.
- Under Scope, copy and paste the code below into the appropriate blocks. Adjust as needed.
EVALUATION codeA simple 'exit 1' will suffice to ensure that the Remediation code will execute every time this Policy runs:
#!/bin/bash
exit 1REMEDIATION 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 - Under the Schedule section, configure the scheduling of the Worklet Policy as per usual.
- 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).