Crontab starting audio player

Asked by mrbeardy

I need to run an audio file from a cron job. This works in a crontab:

1,5 * * * * play /home/username/bin/audio.wav

Problem is that if another program such as Totem or VLC is using the sound card then it won't play.

As a work around I have been trying to get VLC or Totem to play the files instead as they don't mind being interrupted or playing over the top of each other. This works on the command line:

totem /home/username/bin/audio.wav

or

vlc /home/username/bin/audio.wav

However when you put them in a crontab they fail to execute, ie any of the following:

1,5 * * * * totem /home/username/bin/audio.wav
1,5 * * * * /usr/bin/totem /home/username/bin/audio.wav
1,5 * * * * vlc /home/username/bin/audio.wav
1,5 * * * * /usr/bin/vlc /home/username/bin/audio.wav

I don't have access to email messages sent form the crontab but accessing the logs using this:

cat /var/log/syslog | grep -i cron

Shows the cron run with nothing that looks like an error

Ideas?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu cron Edit question
Assignee:
No assignee Edit question
Solved by:
Drew Feragen
Solved:
Last query:
Last reply:
Revision history for this message
Best Drew Feragen (drewferagen) said :
#1

Try appending DISPLAY=:0 in front of your command.

Here is the crontab I use to wake up:

30,45 6 * * 1,2,3,4,5 DISPLAY=:0 beep-media-player /home/aferagen/wakeup.m3u -p
0 10,13 * * 0,6 DISPLAY=:0 beep-media-player /home/aferagen/wakeup.m3u -p

In my experience DISPLAY=:0 is needed for scheduling anything with a GUI.

Revision history for this message
mrbeardy (mrbeardy) said :
#2

Thanks Drew Feragen, that solved my question.

Revision history for this message
Daniel Hahler (blueyed) said :
#3

You need to also export XAUTHORITY when using e.g. "play" (from the "sox" package) to play some sound.

See http://askubuntu.com/questions/64033/mplayer-can-not-play-audio-from-cron-when-ncmpcpp-playing/132266#132266