Skip to main content
Topic: cronie and sound (Read 725 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

cronie and sound

This has worked for a long time through crontab

Code: [Select]
SHELL = /bin/sh 
CRON_TZ = 'America/New_York'
34 19 * * * /usr/bin/amixer -c 0 set Master playback 100\% >> /dev/null
35 19 * * * /usr/bin/mplayer /home/ruben/docs/Rav\ Shorr\ Shium/*mp3 >> /dev/null
40 05 * * * /usr/bin/killall mplayer >> /dev/null
40 05 * * * /usr/bin/amixer -c 0 set Master playback 70\% >> /dev/null

Suddenly it stopped work ...

Oct 21 19:34:01 flatbush crond[30857]: (ruben) RELOAD (/var/spool/cron/ruben)                          
Oct 21 19:34:01 flatbush CROND[31731]: (ruben) CMD (/usr/bin/amixer -c 0 set Master playback 100% >> /dev/null )
Oct 21 19:34:01 flatbush CROND[31730]: (ruben) CMDEND (/usr/bin/amixer -c 0 set Master playback 100% >> /dev/null )
Oct 21 19:35:01 flatbush CROND[31748]: (ruben) CMD (/usr/bin/mpg123 /home/ruben/docs/Rav\ Shorr\ Shium/*mp3 >> /dev/null)
Oct 21 23:35:01 flatbush rtkit-daemon[8419]: Supervising 12 threads of 11 processes of 1 users.
Oct 21 23:35:01 flatbush rtkit-daemon[8419]: Supervising 12 threads of 11 processes of 1 users.
Oct 21 23:35:01 flatbush rtkit-daemon[8419]: Supervising 12 threads of 11 processes of 1 users.
Oct 21 23:35:01 flatbush rtkit-daemon[8419]: Supervising 12 threads of 11 processes of 1 users.
Oct 21 23:35:01 flatbush rtkit-daemon[8419]: Supervising 12 threads of 11 processes of 1 users.
Oct 21 19:35:01 flatbush pulseaudio[31755]: [pulseaudio] cli-command.c: stat('/etc/pulse/default.pa.d'): No such file or directory
Oct 21 19:35:01 flatbush pulseaudio[31755]: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Oct 21 19:35:01 flatbush pulseaudio[31755]: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Oct 21 19:36:55 flatbush crontab[31790]: (ruben) BEGIN EDIT (ruben)
Oct 21 19:37:06 flatbush crontab[31790]: (ruben) REPLACE (ruben)
Oct 21 19:37:06 flatbush crontab[31790]: (ruben) END EDIT (ruben)
Oct 21 19:38:01 flatbush crond[30857]: (root) CAN'T OPEN (/etc/crontab): No such file or directory
Oct 21 19:38:01 flatbush crond[30857]: (ruben) RELOAD (/var/spool/cron/ruben)


I really need this to work.  I need to work in the morning and cure patients of their deadly diseases.

Re: cronie and sound

Reply #1
OK - so I removed all of gnome and all pulseaudio and it is now working.  But thi s is not a rational solution.  I want to do gnome development.  There to be a rational solutions to using this and gnome.

 

Re: cronie and sound

Reply #2
It looks like the amixer command succeeds but the mplayer command fails, would it work with another player like say vlc instead?

Re: cronie and sound

Reply #3
It looks like the amixer command succeeds but the mplayer command fails, would it work with another player like say vlc instead?

No - the problem is pulseaudio won't allow for access by cron of the sound

Re: cronie and sound

Reply #4
The problem is you aren't exporting DISPLAY. You need to prepend the command which needs it with /usr/bin/env DISPLAY=:0 (hardcoded, not flexible) or have a dedicated script which will more reliably get the active display and set the variable:

Code: [Select]
#!/bin/sh
# Save the file as setdisp in a directory in your PATH
# with chmod 755 /path/to/setdisp
# This is the X.Org version, for Wayland you need a different, but similar approach

disp=$(pgrep -a Xorg | sed 's/.*\(:[0-9]\+\).*/\1/')
[ -z "$disp" ] && { echo "X not running" >&2; exit 1; }
/usr/bin/env DISPLAY=$disp $*
And then instead of calling my_program call your program with:
Code: [Select]
/path/to/setdisp my_program

P.S: You seem to use redirection arrow for appending output to /dev/null, that is not necessary if you want to discard output. Just use normal redirection:
Code: [Select]
my_command >/dev/null
To also redirect stderr, use
Code: [Select]
my_command >/dev/null 2>&1
However, in this case, I would instead save the output to a log, to see any errors output by those commands:
Code: [Select]
my_command >> /home/my_username/my_command.log 2>&1
Of course, ensure the file exists with
Code: [Select]
touch /home/my_username/my_command.log