How to Set Up User Notifications for Linux Devices
This guide provides instructions on setting up user notifications for Linux devices using Automox Worklets. These notifications can alert users to take action, such as saving their work before a reboot.
Prerequisites
- Zenity Installation: Ensure the zenity package is installed. Use sudo apt-get install zenity (Debian-based) or sudo yum install zenity (Red Hat-based).
- Sudo Access: The script requires administrator privileges to execute.
- Desktop Environment: Notifications rely on a desktop environment with an active display session.
Steps to Implement
- Create a Custom Worklet Policy:
- Navigate to Manage > Policies in the Automox console.
- Click Create Policy and select the Linux Worklet section.
- Assign a descriptive name to the Worklet Policy and associate it with appropriate Group(s) or use Device Targeting.
- Enter the Code:
Under the Scope section, use the following:
Evaluation Code:
#!/bin/bash
exit 1
This ensures the Remediation Code executes every time.
Remediation Code:
#!/bin/bash
#================================================================
# Sends a notification to a Linux desktop
#================================================================
## Configurable Items
title='Message from Automox'
message_text='Updates require reboot: Please save your work.'
width=400
height=100
timeout_duration=60 # seconds
## Send Notification
if command -v zenity &>/dev/null; then
who | awk '{print $1}' | sort | uniq | while read -r user; do
sudo -u "$user" DISPLAY=:0 \
zenity --warning --title="$title" --text="$message_text" \
--width="$width" --height="$height" --timeout="$timeout_duration"
done
else
echo "Zenity is not installed. Please install Zenity and try again."
fi
- Schedule the Policy:
- Under the Schedule section, configure the frequency for running the Worklet Policy.
- Click Create Policy.
Testing the Setup
- Assign the Worklet Policy to a test group.
- Run the Worklet manually to verify notifications appear as expected.
- Check the system logs if the notifications do not appear.
Additional Tips
- Combine this Worklet with existing scripts for patch management or automated reboots.
- Ensure notifications are displayed in environments with active user sessions.