Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up a script, which executes an mplayer command, in order to play audio in crontab. It will be executed in a special set time, but this script can not play audio when ncmpcpp (a front-end for mpd, aka. Music Player Daemon) is playing music. But this script can play audio when I execute it from terminal like this:

sh bin/   

I try to get output from either crontab or script, but to no avail. I guess some setting in ncmpcpp or mplayer is wrong, or mpd is using same daemon with crontab's daemon.

  • Anyway, I can not find out the solution. If you know, please help me.
share|improve this question
up vote 1 down vote accepted

The problem seems to be that mpd runs under user mpd per default (as a system daemon) and is thus unable to join your sessions' pulseaudio mixer, therefore it hogs the sound card output via alsa or even oss. In my answer, I assume that you are logged in and that the crontab is yours and not the system crontab.


Depending on your priorities, you have a lot of options that mostly circle around the idea teaching mpd to not hog the sound and use pulseaudio instead. See the mpd wiki.


You can configure mplayer to default to pulseaudio by placing a line ao=pulse in ~/.mplayer/config but pulseaudio should pick it up nicely with its alsa plugin.

share|improve this answer
I have set ao=pulse in ~/.mplayer/config. but set mpd on pulseaudio is so complex. But it this splution is good. – stardiviner Nov 21 '11 at 4:41
This doesn't work for me. mplayer just waits until mpd is paused, then plays the sound. – Exeleration-G Dec 28 '15 at 9:06

In your crontab, please add this to the command section

export DISPLAY=:0.0 && sh /bin/

The export DISPLAY=:0.0 is required to run Graphical apps.

share|improve this answer
It does not help for sound though.. the error from cron for e.g. ogg123 is: ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave ERROR: Cannot open device alsa. – blueyed May 5 '12 at 18:27

When using e.g. play (from the sox package), the following information needs to be exported:

export DISPLAY=:0
export XAUTHORITY=/home/YOURUSERNAME/.Xauthority
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.