Error in spawning a dbus-launch - what is that?
Asked Answered
S

2

12

I like to run a cron that snapshots a cam like this:

* 9-17 * * 1-5 vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1

But when the cron runs it just throws an error I don't understand:

** Message:
Failed to get session bus:
Error spawning command line 'dbus-launch --autolaunch=55644972b3c91c1d24d83d8252721f00 --binary-syntax --close-stderr':
Child process exited with code 1

In the web I find no clean or good documentation what that is. Can you help me figure it out?

Skaggs answered 29/11, 2013 at 12:21 Comment(0)
J
5

From what I can tell, you may need to either:

  • Set the display variable (Note that it might not be 0, could be 1 or even 2):

     export DISPLAY=:0
    
  • Launch a dbus-session:

     dbus-launch
    
  • Set the dbus variable:

     export $(dbus-launch)
    

In your case with a Cron job you can set environment variables like this:

env VARIABLE=VALUE <command>

So for option 1 your job would look like this:

* 9-17 * * 1-5 env DISPLAY=:0 vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1

For option 2 you can separate the two commands using &&, like this:

* 9-17 * * 1-5 dbus-launch && vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1

Something similar for option 3:

* 9-17 * * 1-5 export $(dbus-launch) &&vlc -I dummy v4l2:///dev/video0 --video-filter scene --no-audio --scene-path /home/foo/tmp/cam --scene-prefix snapshot --scene-format png vlc://quit --run-time=1
Jeb answered 26/6, 2020 at 19:12 Comment(2)
Note that this spawns two instances of dbus and the first one will not be used. The step 2. should already look like the 3. - export $(dbus-launch)Endothelioma
@Endothelioma Sorry these should not have been written as steps, 1, 2, and 3 are three individual solutions.Jeb
S
1

Had the same issue when trying to use notify-send in a bash script that required root privileges.

Adding

export $(dbus-launch)

to the beginning of the bash script did the trick for me.

Saponin answered 27/1 at 12:44 Comment(1)
In WSL I added export $(dbus-launch) at the end of .bashrc and in the next Ubuntu window, it works (in my case virt-manager saves its setting for the next run). Thank you :-)Slipnoose

© 2022 - 2024 — McMap. All rights reserved.