I have read similar posts here, here, here and here that mentioned some environment variables DISPLAY
and DBUS_SESSION_BUS_ADDRESS
. Setting them at the top of my user crontab enabled notify-send to work in my user crontab. However, the exact same crontab does not work if set in the sudo crontab -e
, why not? And how can I make it work?
test.sh
#! /bin/bash
env > $1
notify-send "I want to see this"
crontab -e
SHELL=/bin/bash
PATH="/usr/bin:/home/ripytide/scripts/"
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DISPLAY=:0
* * * * * test.sh /home/ripytide/crontab.env
sudo crontab -e
SHELL=/bin/bash
PATH="/usr/bin:/home/ripytide/scripts/"
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DISPLAY=:0
* * * * * test.sh /home/ripytide/sudocrontab.env
crontab.env
SHELL=/bin/bash
PWD=/home/ripytide
LOGNAME=ripytide
_=/usr/bin/env
HOME=/home/ripytide
LANG=en_GB.UTF-8
USER=ripytide
DISPLAY=:0
SHLVL=1
PATH=/usr/bin:/home/ripytide/scripts/
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
sudocrontab.env
SHELL=/bin/bash
PWD=/root
LOGNAME=root
_=/usr/bin/env
HOME=/root
LANG=en_GB.UTF-8
USER=root
DISPLAY=:0
SHLVL=1
PATH=/usr/bin:/home/ripytide/scripts/
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus