I am trying to setup a cronjob to execute a script every minute.
My test.sh script:
#!/bin/bash
notify-send hello
I have made the above script executable.
Here is my crontab -e file's output http://pastie.org/4316348
Now when I see the output of syslog it shows that the cronjob is getting executed every minute but I am not able to see my desired output.
syslog:
Jul 24 17:42:01 noob CRON[5291]: (noob) CMD (/home/noob/test.sh)
Jul 24 17:43:01 noob CRON[5364]: (noob) CMD (/home/noob/test.sh)
Jul 24 17:44:01 noob CRON[5374]: (noob) CMD (/home/noob/test.sh)
Jul 24 17:45:01 noob CRON[5386]: (noob) CMD (/home/noob/test.sh)
So, I am wondering what am I doing wrong here and why I am not able to see my desired output(notification).
At a guess, notify-send is a program which uses X; in which case, it needs to know the display number of the X display to show the notification on. When you start a terminal in X, that's set automatically, but a crontab doesn't have that environment.
As a simplistic start, try changing your crontab line to this:
* * * * * DISPLAY=:0.0 /home/noob/test.sh
On some systems, DISPLAY=:0.0 /path/to/shell_script.sh might not work.
Instead the below script works :
#! /bin/bash
export XDG_RUNTIME_DIR=/run/user/$(id -u)
set -x
notify-send "Hello"
Crontab will look as follows.
* * * * * bash /path/to/shell_script.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With