The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 6,778β€…    Votes:  11β€…
Tags: sound   cron  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

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 20, 2023    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/ /home/ME/bin/bigben/Clock_Chime_01.ogg >/dev/null 2>&1 # JOB_ID_75
    (... SNIP ...)
45 0-23 * * * /home/ME/bin/ /home/ME/bin/bigben/Clock_Chime_15-3.ogg >/dev/null 2>&1

Then create your /usr/local/bin/ script:

export XDG_RUNTIME_DIR="/run/user/1000"
mplayer -really-quiet "$1" -volume 100

Remember to mark the script executable by using:

chmod a+x /usr/local/bin/
⇧ How to make speaking clock (via cron and festival tts) work while playing music 17.10 No sound from cron jobs  β‡©