How to execute shell script via crontab?

Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.

Make it look like this:

#!/bin/sh
notify-send "hi welcome"

and make sure the script is executable:

ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh

Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.


Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.

*/1 * * * * cd /home/hacks && sh notify.sh

To make the script executable, we have to do:

chmod +x home/hacks/notify.sh

Here i run this script for every one minute ... By doing below script, you can write it in a log file to find whether its working

write log

*/1 * * * * cd /home/hacks && sh notify.sh>>test.log

send mail

*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" [email protected]

4 hypothesis:

  • the cron daemon is not running (do a ps axfww | grep cron and check)

  • the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the cron environment and it does not know "who to talk to", so to speak.

  • your script is not executable

  • the home/ path in the crontab script is relative to the user the scripts gets executed as. Try using the full path