I'm trying to create something like a watch does. The beep sound indicating that an hour has been passed.

So I opened the crontab(sudo crontab -e) and wrote this line(there are five asterisks just for testing) :

* * * * * /usr/bin/mplayer /tones/beep.wav > /home/user/cronlogs/cron.log

But the beep sound does not play. I tested it manually in the terminal and the beep plays normally.


  • Paulo
  • 2
    Usually when something works on the command line but doesn't work in crontab, it's due to changed environment variables. Standard error might be helpful; try adding 2>&1 to the end of that line, so that it goes into cron.log as well. (Also, you probably want >> rather than >, so that each run doesn't overwrite the log from the one before it.)
    – Tom Hunt
    Nov 13, 2015 at 0:29
  • mplayer probably expects an X server to create a window on. Use a command line tool like aplay instead.
    – cas
    Nov 13, 2015 at 0:32
  • Hello, I followed your instructions and I got the log message now. The comment about environment variables make a lot of sense to me, thanks for that. But I still have problems, using 'aplay' still gives me error, now the log message is : ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave aplay: main:722: audio open error: Device or resource busy. It has to do with crontab permissions? I never changed it's permissions.
    – Paulo Mann
    Nov 13, 2015 at 1:43
  • Can you play sounds from two separate processes simultaneously?
    – user140866
    Nov 13, 2015 at 4:59
  • For some reason, when I restarted my computer, the sound started to play, but anything besides the beep sound does not play. I Changed the output sound to "Analog Output : Built-in Audio" and other sounds now play normally, but again, the beep sound from crontab does not play. With "HDMI / DisplayPort" the beep sound plays normally, but not other sounds. @siblynx yes, I made a test and I can play sounds from two separate processes simultaneously.
    – Paulo Mann
    Nov 13, 2015 at 12:16

5 Answers 5


step 1

xuser@mbs:~$ env|grep -i runt

step 2 create file play.sh (remember about chmod)

export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/mpg123 $1

step 3 crontab -e

хх * * * * /home/xuser/bin/play.sh /home/xuser/Музыка/demo_moya_vesna.mp3

step 4

$%)) ata-ta %:) enjoy
  • Nice. It worked! Or as a workaround you could add a XDG_RUNTIME_DIR=/run/user/1000 somewhere around the top of your crontab. And directly use the play command without the need of play.sh file.
    – AnnShress
    May 20, 2021 at 2:58
  • @AnnShress . in the play.sh script, you can adjust the volume, and other parameters. IF!!! the sound is monophonic (from one speaker), you need to use another audio player. For example mplayer.
    – Aliskin
    Jun 25, 2022 at 3:00
  • talking clock (ru) tbs-mbs.net/post-745-pg1-sort1
    – Aliskin
    Jun 25, 2022 at 3:04

You probably use pulseaudio...

Therefor you should use play instead of aplay.


* * * * * /usr/bin/play /tones/beep.wav > /home/user/cronlogs/cron.log

I have a talking clock using espeak.

It may help in your case, if you add the user ID that should play sounds to the audio group (at the end of the line starting with audio in the file /etc/group).

So add root if you want it to play via sudo crontab -e. (This was only necessary for me with regular user IDs (not for root), but this may differ between linux distros.)

  • User ID (id -u) is a number. Did you mean that? I'm having the same issue with @hourly XDG_RUNTIME_DIR=/run/user/1000; /usr/local/bin/gtts-cli -l en "Hour $(/bin/date +\%l)" | /usr/bin/play -t mp3 -, where 1000 is my id -u
    – Pablo A
    Feb 12, 2021 at 21:14
  • @PabloA, I meant the name. for example sudodus, which works for me. Did you try with espeak, for example /bin/date +\%l|espeak
    – sudodus
    Feb 12, 2021 at 22:01

Enter the following in contab

# Terminal command: crontab -e

* * * * * su -c "paplay /usr/share/sounds/gnome/default/alerts/glass.ogg" -s /bin/sh <username>

Hope this helps.


Tom Hunt is right, it's the environment. And I go with cas and use aplay.

In your crontab file, add something like

* * * * * aplay /tones/beep.wav

If your user id happens to differ, replace 1000 above with the output of id -u. This will beep once a minute. For the original objective, beep once a hour, replace the first * with 0.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .