Solution with anachron
and notify-send
The answer to the problem is anachron that executes commands automatically as root, where root needs access to the dbus session of the main user.
1. Give root access to your desktop session (as user)
To let the root user access the default user's desktop, you first need to set the DBUS_SESSION_BUS_ADDRESS
variable. By default cron does not have access to the variable that changes every system start. To remedy this put the following script in your home directory and call it ~/dbus-session-export
#!/bin/sh
touch ~/.dbus/Xdbus
chmod 600 ~/.dbus/Xdbus
env | grep DBUS_SESSION_BUS_ADDRESS > ~/.dbus/Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> ~/.dbus/Xdbus
exit 0
Give it executable rights:
chmod +x ~/dbus-session-export
And call it in your startup programs.
This will create/update the file ~/.dbus/Xdbus
containing the required Dbus evironment variable for anachron to use at each system boot.
2. Cron script (as root)
Put a script in the folder /etc/cron.daily/
and make it executable:
sudo touch /etc/cron.daily/rkhunter-check
sudo chmod +x /etc/cron.daily/rkhunter-check
Edit the file gksu gedit /etc/cron.daily/rkhunter-check
#!/usr/bin/env bash
sleep 1800 # wait 30 minutes in case the script is called directly at boot
MAINUSER="$(awk -F: '$3==1000{print $1}' /etc/passwd)"
if [ -r "/home/$MAINUSER/.dbus/Xdbus" ]; then
. "/home/$MAINUSER/.dbus/Xdbus"
fi
su $MAINUSER -c 'notify-send "starting rkhunter scan... "'
rkhunter --checkall --report-warnings-only | while read OUTPUT; do
if [ "$OUTPUT" != "" ]; then
OUTPUT="${OUTPUT//[\`\"\']/}"
su $MAINUSER -c $"notify-send \"rkhunter: $OUTPUT\""
fi
done
This will run the script every day once and if the rkhunter run generates any output (only warnings), this script will show up as a notification for each warning in the top right of your screen as user
Source: