You are not logged in.
I'm trying hard to prevent getting this error from each user cronjob (cronie) that runs my python scripts.
Methods I've tried:
- putting DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus and DISPLAY=:0 in cron head
- * * * * * env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus DISPLAY=:0 "path/script.py"
- * * * * * /usr/bin/xuserrun "path/script.py"
- * * * * * "path/script.py" > /dev/null 2>&1 # this denies me a possibility to get other meaningful errors I need to catch
- importing environment from within python scripts
gui_env_dynamic = {
'DISPLAY': current_display, # Dynamic display detection
'XAUTHORITY': xauthority_file, # Dynamic XAUTHORITY detection
'DBUS_SESSION_BUS_ADDRESS': f'unix:path=/run/user/{user_id}/bus',
'HOME': home,
'USER': person,
'LOGNAME': person,
'PATH': '/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl',
'XDG_RUNTIME_DIR': xdg_runtime,
'XDG_SESSION_ID': '1',
'XDG_SESSION_TYPE': 'x11',
'XDG_SESSION_CLASS': 'user',
'XDG_SEAT': 'seat0',
'XDG_CURRENT_DESKTOP': 'XFCE',
'XDG_MENU_PREFIX': 'xfce-',
'XDG_CONFIG_DIRS': '/etc/xdg/xdg-xfce:/etc/xdg',
'XDG_DATA_DIRS': '/usr/share/xfce4:/usr/local/share:/usr/share',
'XDG_CONFIG_HOME': xdg_config,
'XDG_DATA_HOME': xdg_data,
'XDG_CACHE_HOME': xdg_cache,
'XDG_VTNR': '2',
'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0',
'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0',
'XDG_SESSION_DESKTOP': 'XFCE',
'PRIMARY_DISPLAY': 'eDP1',
'ORIGINAL_XDG_CURRENT_DESKTOP': 'XFCE',
# GNOME Keyring environment variables
'GNOME_KEYRING_CONTROL': f'{xdg_runtime}/keyring',
'GNOME_KEYRING_PID': '',
'SSH_AUTH_SOCK': f'{xdg_runtime}/keyring/ssh'
}.xinitrc contents:
source /etc/X11/xinit/xinitrc.d/50-systemd-user.sh
exec startxfce4- I've read docs about cron, running GUI apps, env and whatnot, yet still haven't figured it out properly.
- Using both laptop display and external monitor (tried DISPLAY=:0.0 also)
Any idea how to set display right?
Last edited by sebastian-65 (2025-07-11 16:50:41)
I'm not the sharpest tool in the shed. Say it to me like I'm 5, please!
Arch Linux | ZFS | systemd | Xfce/X11/SDDM | ASUS S435 | Intel CPU 11th gen | Intel TigerLake-LP GT2 | 16GB RAM
Offline
Try something like this:
cron
* * * * * path/run.shrun.sh
#!/bin/sh
export XAUTHORITY="${HOME}/.Xauthority"
export DISPLAY=":0"
exec path/script.pyThe "export" is the key as it passes the environment variables to the child process.
Last edited by karabaja4 (2025-07-11 12:21:14)
Offline
I've found out I had perhaps a garbled .Xauthority file, so I replaced the contents temporary file (from xauth info) and it worked automagically again!
You've definitely shown me the way, thank you stranger!
I'm not the sharpest tool in the shed. Say it to me like I'm 5, please!
Arch Linux | ZFS | systemd | Xfce/X11/SDDM | ASUS S435 | Intel CPU 11th gen | Intel TigerLake-LP GT2 | 16GB RAM
Offline
Also https://gist.github.com/AladW/de1c5676d93d05a5a0e1
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Online