Skip to content

[Help | Bash] I'm trying to run a script via cron, but it fails due to dbus-daemon launch error

Good Morning Redditors,

I've spent the better half of my night trying to develop an "app" using python. I've gotten it work, and I have no issues there.

However, when i try to schedule the python script to be executed via cronie, it fails with the following error: CMDOUT (dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11)

Worth mentioning that I'm using a bash script to call my python script, and I have set the paths for all required packages. The script runs perfectly fine when I manually execute it. Afaik, It has something to do with the PATHS for X11.

Any suggestions would be greatly helpful.

Take care and have a great day, Dave.

3 points6 comments
Open on Reddit
About this post
Posted
Archived
Score
3 · 100% up
Kind
Text
ID
85tsun

Author

4
posts
5
comments
3
media
View profile

7 comments

Along with DISPLAY=:0 being set correctly, you can also do this with systemd user timer/unit files.

2 points

I second this. Learn how to use systemd units. The learning curve looks more daunting than it really is. They are really quite simple to write and I find them to be highly reliable.

1 points

I encountered a similar problem before trying to run notify-send with cron I edited the arch cron wiki page with solution see Running X.org server-based applications section

https://wiki.archlinux.org/index.php/Cron

Cron does not run under the X.org server therefore it cannot know the environmental variable necessary to be able to start an X.org server application so they will have to be defined. Sending values to dbus. So it needs to tell dbus to connect to the right bus. The address can be found by examining DBUS_SESSION_BUS_ADDRESS environment variable and setting it to the same value. Therefore: Therefore in my case it was

DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

adding this to crontab.or like this

17 02 * ... env DBUS_SESSION_BUS_ADDRESS=your-address foo command

at least i think this is your problem!

1 points

4 years later I ran into a similar issue as OP: a python script with pystray started from cron giving a dbus error. Took me ages to find your comment, but setting DBUS_SESSION_BUS_ADDRESS solved it!

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.