Run Gui Programs Under Cron, Monitor Root Filesystem Disk Usage And Send Alarm

linux
cron
gui programs
notify-send
disk usage monitoring
root filesystem
10% free space
The article provides instructions on running GUI programs with cron in Linux and monitoring root filesystem disk usage using `notify-send` and setting environment variables. It also includes a script for disk usage monitoring that sends alerts when the root filesystem has less than 10% free space.
Published

June 19, 2024


the ultimate solution:

copy all current user environment variables to crontab.


to run notify-send you have to set DBUS_SESSION_BUS_ADDRESS


to run other gui programs you set DISPLAY and XAUTHORITY


wall works for tmux and ssh sessions but not gnome-terminal.

in kde everything works fine. install konsole instead.


script for monitoring disk usage:

#!/bin/bash
used_percentage=$(df / | awk 'NR==2 {sub(/%/, "", $5); print $5}')
alarm_message="Root filesystem has less than 10% free space."
# Compare the percentage with the number 90
if [ "$used_percentage" -lt 90 ]; then
echo "Disk is ok."
else
wall $alarm_message
notify-send $alarm_message
fi