sound in cronjob problem

Hi,

I have a little cronjob placed in /etc/cron.d/mine:


> -0,30 * * * * cer /home/cer/bin/avisar_hablando hora  >> /tmp/avisar_hablando.log

The script does this:


> #!/bin/bash
> MAILTO="nobody"
>
> TEMPORAL=`mktemp /tmp/decir.wav.XXXXXXXXXXXXX`
> ERROR=$?
> case $ERROR in
>   0) ;;
>   *) echo "Error $ERROR in mktemp"
>      exit
>      ;;
> esac
>
>
> case "$1" in
>
>         hora)
>              LANG=es_ES.ISO-8859-1 LC_ALL=es_ES.ISO-8859-1 /bin/date +"Es %e de %B, y son las %k horas y %-M minutos " | espeak -v es --stdin -a 20 -w $TEMPORAL
>         ;;
> esac
>
> if test -f $TEMPORAL ; then
>         ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay -q $TEMPORAL
>         rm $TEMPORAL
> fi

Or, in short:


> LANG=es_ES.ISO-8859-1 LC_ALL=es_ES.ISO-8859-1 /bin/date +"Es %e de %B, y son las %k horas y %-M minutos " | espeak -v es --stdin -a 20 -w /tmp/temporary
> ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay -q /tmp/temporary

Or, if you prefer in English:


> /bin/date +"%B %e, %k hours %-M minutes " | espeak -v en --stdin -a 20 -w /tmp/temporary
> ALSA_CONFIG_PATH=/etc/alsa-pulse.conf SDL_AUDIODRIVER=pulse /usr/bin/aplay -q /tmp/temporary

The idea is a speaking clock: it speaks the time every half hour. If I
call it from the command line, it works fine. If it runs as a cronjob,
it works for weeks, then suddenly it stops working like this:


ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
aplay: main:731: audio open error: Device or resource busy

I inmediately run it from the CLI, and it works.

Perhaps something else instead of “aplay” to play the WAV file? I’ll try
‘paplay’… the problem is, it might not work if the desktop is not
loaded, because then pulse is not loaded.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On 2013-06-26 12:53, Carlos E. R. wrote:

> Perhaps something else instead of “aplay” to play the WAV file? I’ll try
> ‘paplay’… the problem is, it might not work if the desktop is not
> loaded, because then pulse is not loaded.

Nope. paplay fails with:

Connection failure: Connection refused
pa_context_connect() failed: Connection refused


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)