Skip to main content
5 of 5
edited tags

notify-send from root cron

On my system, notify-send requires 3 enviorment variables to run, which are kept in a file which is generated automatically on logon:

/home/anmol/.env_vars:

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-PwezoBTpF3 export DBUS_SESSION_BUS_ADDRESS XAUTHORITY=/home/anmol/.Xauthority export XAUTHORITY DISPLAY=:0 export DISPLAY 

And, in the crontab buffer, I have entered this:

PATH=/home/anmol/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin * * * * * /home/anmol/display-notif.sh 

where display-notif.sh contains:

#!/usr/bin/env bash . /home/anmol/.env_vars notify-send 'hello' 

Although I am able to run notify-send from non-sudo cron (crontab -e) through this setup, I am unable to do so from sudo cron (sudo crontab -e).

I also tried checking if there are any errors being generated:

* * * * * /home/anmol/display-notif.sh 2>/home/anmol/log 

But that log file is empty.

How do I make it work from sudo cron ?

I am using Ubuntu 16.04.