Linux – How to execute shell script via crontab

crontablinux

I have a notify.sh script that looks like:

notify-send "hi welcome"

My crontab notification for 2 PM:

0 14 * * * home/hacks/notify.sh

However, this doesn't work. What is the problem?

Best Answer

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.

Related Question