1

I did crontab -e then added */2 * * * * /usr/bin/notify-send "test", which is supposed to send a notification every 2 minutes, but it's not working.

The crontab file looks like this.

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

*/2 * * * * /usr/bin/notify-send "test"

1 Answers1

1

I think Cron is running as system daemon and don't know about your desktop environment session, though it is needed to show notifications. You could write script that will send notification and sleep for 2 minutes and run it from your user in background. Also if you want exactly Cron you could create script that will at first export desktop identifier export DISPLAY=:0, then call notify-send and call this script from Cron or simply replace your Cron line with */2 * * * * DISPLAY=:0 /usr/bin/notify-send "test".

Note - for me it worked in Ubuntu 16.04 but not in Kubuntu 19.10. Haven't tested on other system versions.

  • export DISPLAY=:0 didn't make notify-send work for me. In any case, eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; worked. – Angular Orbit Oct 29 '19 at 07:48
  • @AngularOrbit, you haven't specified which Ubuntu version you use and seems that notify-send works differently on different desktop environments and different versions. I've added note to my answer and specified on which version I've made it to work and on which I could not. – Dmitriy Vinokurov Oct 29 '19 at 07:51