Issue
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).
Solution
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
Answered By - Ashe Answer Checked By - Pedro (WPSolving Volunteer)