I want to use crontab to play recordings of the big Ben every hour and at 15,30 and 45 minutes.
So far I'm using mplayer2 and the following tasks:
0 1,13 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_01.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_75
0 2,14 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_02.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_76
0 3,15 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_03.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_77
0 4,16 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_04.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_78
0 5,17 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_05.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_79
0 6,18 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_06.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_80
0 7,19 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_07.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_81
0 8,20 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_08.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_82
0 9,21 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_09.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_83
0 10,22 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_10.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_84
0 11,23 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_11.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_85
0 0,12 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_12.ogg -volume 100 >/dev/null 2>&1 # JOB_ID_86
15 0-23 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_15-1.ogg -volume 100 >/dev/null 2>&1
30 0-23 * * * mplayer -really-quiet ~/bin/bigben/Clock_Chime_15-2.ogg -volume 100 >/dev/null 2>&1
45 0-23 * * * mplayer -really-quiet ~/bin/bigben /Clock_Chime_15-3.ogg -volume 100 >/dev/null 2>&1
But most of the time it does not work. Sometimes it does play the sound but delayed. ie. supposed to play at 21:15, and it didn't at 21:17 I opened a terminal and played another file with mplayer, after it finished, I heard the one supposed to play 2 min earlier.
Edit:
Now trying with:
* * * * * "/usr/bin/mplayer -volume 100 --ao=pulse /home/myuser/bin/bigben/Clock_Chime_15-1.ogg"
without success.
I do have the feeling like the task stays in some kind of cue.
PS. I can share the sound files.
Best Answer
As per this answer: Can I use cron to chime at top of hour like a grandfather clock? you need to export an environment variable before playing sounds in your cron script:
So rather than calling your music player directly, call a script name in
crontab
like this:ME
with your user name./bigben
and before/Clock
on in the last line of yourcrontab
. I've fixed the error above.~/
shortcut for/home/ME
whichcron
doesn't like. Use full path names incron
.Then create your
/usr/local/bin/big-ben.sh
script:crontab
entry to your scriptRemember to mark the script executable by using: