I'm trying to use a cron job to see when the battery gets lower than a given threshold, and then to send a battery critical notification. However, when I make the cron job execute a script every minute, and make the script send me a notification, it doesn't work.
To make sure that it's not a permissions issue with the script or something causing the cron job to not run, I made the script create a file instead, and it worked. This is the crontab entry:
* * * * * /home/aravk/test.sh
And, to simplify the problem, these are the contents of test.sh
:
#!/bin/sh
/usr/bin/dunstify hi
No notification shows up, however. The script does work when I execute it manually. I also tried setting the DISPLAY
environment variable to :0
by changing the crontab entry to * * * * * export DISPLAY=:0 && /home/aravk/test.sh
, but it still didn't work. How do I send notifications from a script executed by a cron job? I'm on Arch Linux, if it's relevant.
/usr/bin/dunstify hi
? Make surelibnotify
is installed.hi
. Like I said in the question, the script does work when I execute it manually.