I'm getting tired of this issue now, because every version of Ubuntu needs to be treated in another way, but in 14.04 I don't know what to do anymore.

My problem: My PC is starting automatically every day to act as my alert, because a crontab starts a script choosing a music to play, starts Rhythmbox, add the chosen file or list to play queue and plays.

The problem now is, the scripts works perfectly when I'm running it from a terminal, but started by crontab Rhythmbox is mostly not starting.

My crontab:


# m h  dom mon dow   command
*/10 * * * * /scripts/copy_loop.sh &

#start alert
50 6 * * 1 /scripts/alert.sh #mo
50 6 * * 2 /scripts/alert.sh #di
50 6 * * 3 /scripts/alert.sh #mi
50 6 * * 4 /scripts/alert.sh #do
50 6 * * 5 /scripts/alert.sh #fr
30 7 * * 6-7 /scripts/alert.sh #sa/so

The /script/copy_loop.sh script is another script which runs perfectly (but it doesn't have to start a program at all...)

alert-script: #!/bin/bash


exec >> $logfile 2>&1

echo "***********************************" 
echo "* Start ("`date +'%d.%m.%Y %H:%M'`") as `whoami` *" 
echo "***********************************" 

#To avoid heart-attacks ;)
amixer set Master 14

echo "Turning monitors on and waiting 5 seconds." 
#Force Monitor to turn on (grafik bug!)
xset dpms force on
sleep 5

#how many days should a song be blocked?

#Create array of music
music=( "Dubstep von Hannes/1-45 The Sound of Dubstep 4 - Mix 1.mp3" 
    "Purity Ring's Shrines.MP3" 
    "XXYYXX - XXYYXX (Full Album).MP3" 
    "Bonobo/Days to Come Disc 1/"
    "Wisdom - Beautiful Chillstep.mp3"
    "Sizzlebird - Artist Mix.mp3"
    "Yann Tiersen - Amelie Soundtrack.mp3"
    "chillstep mix 2013 vol.3.mp3"
    "Burning Snowflakes Mix.mp3"
    "Parov Stelar - Daylight/"
    "Parov Stelar - Coco/Disc 1/"
    "Parov Stelar - Coco/Disc 2/"
    "Salvation 2 Hour Best of Chillstep Mix.mp3"
    "Lonely Nights Wonderful Chillstep Mix.mp3"
    "Caribou - Swim (Full Album).mp3"
    "Gorillaz Plastic Beach 2010/"
    "Griechenland/Pendulum - Hold Your Colour/"
    "Griechenland/Pendulum In Silico/"
    "Pendulum - Immersion/"
    "Aphex Twin - Selected Ambient Works 85-92.MP3"
    "RJD2 - Deadringer (Full Album).MP3"
    "Deep Cuts/"
    "Silent Shout/"
    "Kosheen/(2002) resist/"
    "Dub_Fx/Everythinks A Ripple/"

for (( i=0; i < 1; i++ )); do
    choose=${music[$(($RANDOM % ${#music[@]}))]}

    #check if song is blocked
    cat /scripts/alertBlock | grep "$choose" > /dev/null

    if [[ $? == 0 ]]; then
        #song is blocked
        echo "$choose is blocked" 

#write to file, so it can't be played the next given days

lines=`wc -l < /scripts/alertBlock`

#cut the last entry
tail -n $(($days - 1)) /scripts/alertBlock > /scripts/.temp
cat /scripts/.temp > /scripts/alertBlock

echo "$choose" >> /scripts/alertBlock

echo "$choose chosen and added to Block-List" 

echo "waiting for Rhythmbox to start" 

rhythmbox-client --no-present & 


#while [[ $ok == false ]]; do
#    rhythmbox-client --check-running
#   if [[ $? == 0 ]]; then
#       ok=true
#   else
#       ok=false
#   fi

sleep 10

echo $choose | grep '/$'

if [[ $? == 0 ]]; then
    cd "/home/julian/Music/$choose"

    echo "Clearing queue" 
     rhythmbox-client --clear-queue 2>&1 

    # To avoid adding pictures and such crap
     rhythmbox-client --enqueue *.mp3
     rhythmbox-client --enqueue *.wav
     rhythmbox-client --enqueue *.ogg
     rhythmbox-client --enqueue *.flac
    sleep 2
     rhythmbox-client --play

     rhythmbox-client --no-start --play-uri="/home/julian/Music/$choose" 2>&1

echo "Music player started. Have Fun!"  

echo "**************************" 
echo "* End ("`date +'%d.%m.%Y %H:%M'`") *" 
echo "**************************"

Basically the script turns on the monitors (works perfectly) adjust the volume (works perfectly) chooses a song and adds it to Block-List (works perfectly) and starts rhythmbox (meh... if it would work the add to playqueue and things would work too...)

In older distributens (12.10 until 13.10) Rhythmbox was starting (adding DISPLAY=:0.0 sudo -u julian or starting via rhythmbox-client --no-present) but now all these things don't work anymore.

The logfile generated when starting the script from terminal:

* Start (28.05.2014 07:56) as julian *
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 31
  Mono: Playback 14 [45%] [-25.50dB] [on]
Turning monitors on and waiting 5 seconds.
RJD2 - Deadringer (Full Album).MP3 chosen and added to Block-List
waiting for Rhythmbox to start
Musicplayer startetd. Have Fun!
* End (28.05.2014 07:56) *

Rhythmbox starts and plays

started by crontab:

* Start (28.05.2014 06:50) as julian *
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 31
  Mono: Playback 14 [45%] [-25.50dB] [on]
Turning monitors on and waiting 5 seconds.
Purity Ring's Shrines.MP3 chosen and added to Block-List
waiting for Rhythmbox to start

(rhythmbox-client:5655): GLib-GIO-CRITICAL **: g_dbus_proxy_new_sync: assertion 'G_IS_DBUS_CONNECTION (connection)' failed
Musicplayer startetd. Have Fun!
* End (28.05.2014 06:50) *

I see the error message here, but I don't know how to get rid of it.

Any help would be appreciated.

Edit: To go one step deeper: There are two interesting questions for me:

  1. Why does every version behave different with its crontab?
  2. Sorry this sardonically question, but what is the reason it is not treated like a typed command of the user? It's obvious that one have to add the DISPLAY=:0.0 statement, but it's absolutely NOT obvious to add the xauthority file, moreover, it doesn't work anyaway.

If rhythmbox starts, then there are two possibilities: 1. It runs in an own instance, so rhythmbox-client doesn't see it. 2. It runs in an encapsulated instance of lightdm/unity, so the Hotkeys on the keyboard are not working and, if closed, the music plays on, but one have to kill it with killall rhythmbox because, starting Rhythmbox via unity in any way (quick-access in audio-panel too), creates a second instance.

I'm only guessing now, but I think, the last two points happens because crontab is doing his work not really in the name of the user it is set up.

Any help would be very appreciated.

Edit 2014-06-16: To bring up more info: It seems like, that it isn't even possible to start any graphical interface in 14.04:

11 8 * * * gnome-terminal
11 8 * * * DISPLAY=:0.0 gnome-terminal

None of the above is working. I'm pretty sure in 13.04 and 13.10 this worked... So still investigating...


rhythmbox-client requires dbus to communicate with rhythmbox. You need to set the environment variable DBUS_SESSION_BUS_ADDRESS for rhythmbox-client. The value can be obtained from the environment with a script like this one.

touch $HOME/Xdbus
chmod 600 $HOME/Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/Xdbus

Run this script after you log in. Then in your alert.sh script you could source $HOME/Xdbus before you run rhythmbox-client.


Try exporting variables before launch script:

50 6 * *  export XAUTHORITY && export DISPLAY=:0 && /scripts/alert.sh #mo

remeber to check wich DISPLAY is connected to the user by typing:

  • Now rhythmbox starts, but rhythmbox-client "don't see" it. It is again running in an own "instance", but thanks for the idea – wolfjuli Jul 3 '14 at 9:44

Now I've chosen a completely different way to solve this problem:

The script now waits with a fifo-file until a command from crontab approaches and then start to work. Because of that I'm possible to start the script on startup and get it worked when crontab says to do so. Now the display manager starts the script and not crontab which now looks like:

#start alert
50 8 * * 1 echo "start;`whoami`;'`date`'" > /scripts/alert/com_fifo #mo
30 7 * * 2 echo "start;`whoami`;'`date`'" > /scripts/alert/com_fifo #di

I'm sorry but posting of the script is hardly possible, because it got split up in multiple files to be able to reuse some functions. Basically it looks like this:


#clear fifo file
rm $com >/dev/null 2>&1 
mkfifo $com

while [[ $hellNotFrozen ]]; do

    #read fifo-file - this statement is blocking!
    inp=`cat $com` #$inp now holds the text pasted into the com-file

    #...do other stuff here        
    rhythmbox-client --enqueue "/data/Music/$chosenFolder/*"
    rhythmbox-client --play


Thanks for all of your answers.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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