Why putting a script in /etc/cron.hourly is not working?
As you've probably seen in the comments to your question, the cronjobs in /etc/cron.hourly
(and the other, similar directories) are executed by run-parts
. run-parts
is a little picky about filenames. By default it doesn't execute files whose filenames contain anything other than (all of those from ASCII)
- uppercase letters
- lowercase letters
- digits
- underscores
- dashes ("minus signs")
So if your script has a filename of for example "myscript.sh", it just is ignored, because run-parts
does not like the dot.
One problem is that you're trying to run a graphical application (notify-send
) from cron. That takes a little tweaking. You need to set XAUTHORITY
and DISPLAY
variables in the crontab so that it can connect to your running X session and you need to set XDG_RUNTIME_DIR
so it can connect to your pulseaudio session. Unfortunately, these need to be set in the crontab itself, so you can't use /etc/cron.hourly
. Instead, run crontab -e
and add these lines:
DISPLAY=":0.0"
XAUTHORITY="/home/YOURUSERNAME/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
0 * * * * /path/to/script.sh
Change the value of XDG_RUNTIME_DIR
to whatever is returned when you echo
them from a terminal. On my system, this is:
$ echo $XDG_RUNTIME_DIR
/run/user/1001
It will probably be the same on yours, but check first. Now, your script will run every hour and should work as expected.
A script ending with .sh
is not executed in /etc/cron.hourly
folder:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=308911
Links or binaries inside a directory handled by run-pars (like /etc/cron.daily) will not run if a period is part of their name.
rename the script
mv /etc/cron.hourly/Hour-sound.sh /etc/cron.hourly/Hour-sound
or put the script-call into
/etc/crontab
which allows the .sh
ending