[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.
About this post
- Posted
- Archived
- Score
- 3 · 100% up
- Kind
- Text
- ID
- 85tsun
7 comments
Along with DISPLAY=:0 being set correctly, you can also do this with systemd user timer/unit files.
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.
set $DISPLAY to the correct value
I did that. I added
DISPLAY:=0In my bash script. However, it still fails to detect it.It should probably be
DISPLAY=:0.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
adding this to crontab.or like this
at least i think this is your problem!
4 years later I ran into a similar issue as OP: a python script with
pystraystarted from cron giving a dbus error. Took me ages to find your comment, but setting DBUS_SESSION_BUS_ADDRESS solved it!