11

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'
    
5
  • 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, 2016 at 7:23
  • @Lnux , Where do I place this line? On .sh file before the notify-send 'crontab' 'test' ? Oct 8, 2016 at 7:44
  • yes in your bash script before notify-send
    – d a i s y
    Oct 8, 2016 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, 2018 at 5:56
  • * * * * * export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ) && DISPLAY=:0 notify-send "Foo bar" Dec 21, 2018 at 15:03

2 Answers 2

13

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.

2
  • In case it helps anyone else, I was able to replace the provided eval ... with: eval "export | egrep 'DBUS_SESSION_BUS_ADDRESS|DISPLAY'". Nov 9, 2017 at 15:10
  • I got a large output which I don't understand, so I replaced the eval ... with the line suggested by @pdoherty926 and I got this output. declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1002/bus" declare -x DISPLAY=":1" . So I changed the next line to DISPLAY=:1 notify-send "Test". Still no notification with crontab
    – kksagar
    Jul 29, 2021 at 9:12
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!'

9
  • 'DISPLAY=:' or 'DISPLAY=' Oct 8, 2016 at 7:02
  • DISPLAY=:0 , the colon is neccessary. Oct 8, 2016 at 7:08
  • I copied and pasted your code using ` crontab -e` using user and root and nothing happens... Oct 8, 2016 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. Oct 8, 2016 at 7:20
  • Do you have to reboot to start? Oct 8, 2016 at 7:25

Not the answer you're looking for? Browse other questions tagged .