test.sh: /usr/bin/notify-send "test"
The following works: bash ~/Documents/test.sh
BUT the crontab never shows the notification. Why?
*/1 * * * * bash ~/Documents/test.sh
test.sh: /usr/bin/notify-send "test"
The following works: bash ~/Documents/test.sh
BUT the crontab never shows the notification. Why?
*/1 * * * * bash ~/Documents/test.sh
To execute any GUI related app from Cron you should export few desktop environment variables. The below solution is based on this answer where are provided more details.
How to launch any GUI related application from
crontab
in Ubuntu 16.04, 17.10, 18.04 and other Ubuntu distributions with GnomeCreate a startup script that will export the desktop environment variables and will launch your application. Let's call it
gui-launcher
. Its content should be (referencs: [1], [2] and [3]):gnome-session
in this part$(pgrep gnome-session -n -U $UID)
with the name of the process of the DE in use, for examplemate-session
. A list of the most Ubuntu DE is presented here. Lubuntu implementation of the same script - here. The script could be used to launch GUI app from TTY or SSH session in the current user's Desktop session.chmod +x gui-launcher
.Then use it within
crontab
in this way:Here is how it works on Ubuntu 17.10 on Wayland:
Here is presented an implementation of the same script over SSH: How to run script (.sh) files in a new terminal after connecting to Ubuntu 16.04 server via ssh?
Here are presented more explanations: Cron job to run python script at reboot does not work.
And one more example: Adjust brightness with xrandr and cron job
Environment for cron and your regular user can be different.
When you're using any scripts in cron better to put full path to them.