10

I really read many tutorials, but crontab doesn't start notify send.

What I've tried:

  1. etc/crontab

    added at the end:

    15 * * * * notify-send 'crontab' 'test'
    
  2. with crontab interface:

    crontab -e
    

    added at the end:

    15 * * * * notify-send 'crontab' 'test'
    
  • 3
    Try to run .sh script by editing eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; – d a i s y Oct 8 '16 at 7:23
  • @Lnux , Where do I place this line? On .sh file before the notify-send 'crontab' 'test' ? – Vitor Abella Oct 8 '16 at 7:44
  • yes in your bash script before notify-send – d a i s y Oct 8 '16 at 7:51
  • on 16.04 this one worked */1 * * * * eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";/usr/bin/notify-send -i appointment -c "im" "Keep Working" – Midhun KM Jul 8 '18 at 5:56
  • * * * * * export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ) && DISPLAY=:0 notify-send "Foo bar" – Saeed Falsafin Dec 21 '18 at 15:03
11

As suggested by @Lnux:

Create a .sh, for example test.sh:

#!/bin/sh
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";

#Code:
DISPLAY=:0 notify-send "Test"

Then set up crontab:

crontab -e

And at the bottom, add:

* * * * * /home/myUser/test.sh

Obs.: you can place your .sh file in another location and don't forget to allow executing it.

  • In case it helps anyone else, I was able to replace the provided eval ... with: eval "export | egrep 'DBUS_SESSION_BUS_ADDRESS|DISPLAY'". – pdoherty926 Nov 9 '17 at 15:10
6

Crontab is running in the background and without specified graphical output it will show nothing. So you should spicify, which output would you like to use. To achieve that, put export DISPLAY=:0 && before you command, e.g.

15 * * * * export DISPLAY=:0 && notify-send 'I am alive!'

  • 'DISPLAY=:' or 'DISPLAY=' – Vitor Abella Oct 8 '16 at 7:02
  • DISPLAY=:0 , the colon is neccessary. – Michal Polovka Oct 8 '16 at 7:08
  • I copied and pasted your code using ` crontab -e` using user and root and nothing happens... – Vitor Abella Oct 8 '16 at 7:14
  • well that is unexpected, because I did the same (except I changed 15 minutes to *) and it works. Try to change the DISPLAY variable to 1 or 2, I have seen it help sometimes, although I don't fully understand why. – Michal Polovka Oct 8 '16 at 7:20
  • Do you have to reboot to start? – Vitor Abella Oct 8 '16 at 7:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.