Referenced these links with no success. Most of them seem to be ubuntu, gnome, and cron syntax specific.
- https://askubuntu.com/questions/298608/notify-send-doesnt-work-from-crontab/346580#346580
- https://stackoverflow.com/questions/16519673/cron-with-notify-send
- How can I get an alert when my battery is about to die in Linux Mint?
Tried export display, dbus, full command path.
Running Arch Linux with dwm. Using fcron and fcrontab -e.
fcrontab
@ 5s /usr/local/shsc/battlow
When I call the script explicitly it works as intended (/usr/shsc/battlow
).
Script
#!/bin/sh
export DISPLAY=:0
battery_level=acpi -b | grep -P -o '[0-9]+(?=%)'
if [ $battery_level -le 100 ]; then
notify-send "Battery low" "Battery level is ${battery_level}%!"
fi
Tried with and without the export DISPLAY=:0
.
Verified display with
$ echo $DISPLAY
:0
# systemctl status fcron
● fcron.service - fcron periodical command scheduler
Loaded: loaded (/usr/lib/systemd/system/fcron.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-05-18 08:36:13 MST; 12min ago
Main PID: 8778 (fcron)
Tasks: 1 (limit: 18916)
Memory: 2.3M
CPU: 3.182s
CGroup: /system.slice/fcron.service
└─8778 /usr/bin/fcron -b
May 18 08:48:08 bar fcron[11367]: Job '/usr/local/shsc/battlow' started for user foo (pid 11372)
May 18 08:48:08 bar fcron[11367]: Job '/usr/local/shsc/battlow' completed
May 18 08:48:13 bar fcron[11383]: Job '/usr/local/shsc/battlow' started for user foo (pid 11388)
May 18 08:48:13 bar fcron[11383]: Job '/usr/local/shsc/battlow' completed