Views:
7,794β
Votes: 15β
Tags:
sound
cron
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1045344
Title:
Help using crontab to play a sound
ID:
/2018/06/10/Help-using-crontab-to-play-a-sound
Created:
June 10, 2018
Edited: June 10, 2018
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
As per this answer: Can I use cron to chime at top of hour like a grandfather clock?6 you need to export an environment variable before playing sounds in your cron script:
export XDG_RUNTIME_DIR="/run/user/1000"
So rather than calling your music player directly, call a script name in crontab
like this:
0 1,13 * * * /home/ME/bin/big-ben.sh /home/ME/bin/bigben/Clock_Chime_01.ogg >/dev/null 2>&1 # JOB_ID_75
(... SNIP ...)
45 0-23 * * * /home/ME/bin/big-ben.sh /home/ME/bin/bigben/Clock_Chime_15-3.ogg >/dev/null 2>&1
- Replace
ME
with your user name. - You had an error (the spaces after
/bigben
and before/Clock
on in the last line of yourcrontab
. Iβve fixed the error above. - You were using
~/
shortcut for/home/ME
whichcron
doesnβt like. Use full path names incron
.
Then create your /usr/local/bin/big-ben.sh
script:
#!/bin/bash
export XDG_RUNTIME_DIR="/run/user/1000"
mplayer -really-quiet "$1" -volume 100
- β$1β is the parameter 1 passed by
crontab
entry to your script
Remember to mark the script executable by using:
chmod a+x /usr/local/bin/big-ben.sh