Why is notify-send not working in Cron?

Why is notify-send not working in Cron?

FWIW, the cron job is running fine which I verified by echoing stuff to a temporary file. It is just the “notify-send” that fails to work.

How to use notify-send on Ubuntu trusty?

* * * * * XDG_RUNTIME_DIR=/run/user/$ (id -u) notify-send Hey “this is dog!” This is sufficient to make notify-send work for me in a cronjob on Ubuntu Trusty: It simply exports the DISPLAY for the user the cronjob is running as. It works for me without setting XAUTHORITY or DBUS_SESSION_BUS_ADDRESS.

Why does crontab not work on Ubuntu 16.04?

If your script in crontab is running as root, the answers above will probably not work. Try this function, which works fine for me in 16.04 : Better to rely on dbus-session process, it should be running for all systems where DBUS_SESSION_BUS_ADDRESS is present.

How to print environment variables from crontab file?

Use printenv for print environment variables from your normal terminal. And then paste all environment variables in starting of crontab file. If your script in crontab is running as root, the answers above will probably not work. Try this function, which works fine for me in 16.04 :

How to use notify-send headless in Linux?

For those on Linux who are comfortable installing Python packages, I just released a notify-send-headless program which is working well for me. It searches /proc for the required username and environment variables and then runs notify-send with these variables (it will use sudo to switch to the required user if necessary).

When to call run _ once function in Cron?

By default cron does not have access to the variable. To remedy this put the following script somewhere and call it when the user logs in, for example using awesome and the run_once function mentioned on the wiki. Any method will do, since it does not harm if the function is called more often than required.