The Cookie Machine - Click here to drag window

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

Views: 5,931β€…    Votes:  8β€…
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: November 24, 2022    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

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

Remember to mark the script executable by using:

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