Ubuntu – Why putting a script in /etc/cron.hourly is not working

cronscripts

I put an executable script in /etc/cron.hourly, but that script didn't run every hour actually it never runs at all.

Here is the script(Hour-sound) that i made:

#!/bin/bash
mplayer ~/Music/sfx_msg-highlight.wv &> /dev/null &
spd-say -r -50 -p 50 -t male3  "The time now is $(date +"%l %p")"
notify-send "It's: " "$(date +"%l %p") now." -i ~/Pictures/"first tee.png" -t 5000

My crontab is:

DISPLAY=":0.0"
XAUTHORITY="/home/naruto/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"

0 * * * * /home/naruto/Hour-sound.sh

While the mplayer and spd-say commands are run correctly, the notify-send is not. I also tried redirecting error to a file:

0 * * * * /home/naruto/Hour-sound.sh 2>/tmp/error

But that showed no output. What am I doing wrong?

Best Answer

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.