This has taken me nearly a day and a lot of reading to get it to work!
Scenario - I wanted a notification every n minutes of any updates available, but this is easily adapted to other uses, just change the script.
- The script (uses auracle & checkupdates):
#!/usr/bin/env bash
# Run by /etc/systemd/system/archup.service + timer
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
echo $(date) > ~/.avail.txt
/usr/bin/checkupdates >> ~/.avail.txt
echo "-----------------------------------------------" >> ~/.avail.txt
/usr/bin/auracle outdated >> ~/.avail.txt
notify-send "$(cat ~/.avail.txt)"
echo $(date) >> ~/test
The export DBUS_SESSION… is the important line, if it is missing, the following error occurs:
Cannot autolaunch D-Bus without X11 $DISPLAY
- The service:
# /etc/systemd/system/archup.service
[Unit]
Description=Service to run update notifier:
[Service]
Type=oneshot
ExecStart=/usr/bin/uup
User=xircon
The important line here is User=<your-user>
. /usr/bin/uup
is a symlink to the script.
- The Timer:
# /etc/systemd/system/archup.timer
[Unit]
Description=Logs some system statistics to the systemd journal
[Timer]
# Explained https://silentlad.com/systemd-timers-oncalendar-(cron)-format-explained
# Testing - Every 1 minute:
#OnCalendar=*:1/1
# Deployment - Every 30 minutes:
OnCalendar=*:0/30:00
Unit=archup.service
[Install]
WantedBy=multi-utimers.target
- Start the timer:
sudo systemctl enable archup.timer --now
A notification can be forced with:
sudo systemctl restart archup.timer