I have a setup as below but its never getting executed.
$ chmod +x /var/tmp/myscript.sh
$ vim /var/tmp/crontab.sh;
* * * * * sleep(10); /var/tmp/myscript.sh
$ crontab /var/tmp/crontab.shNow just, noticed its not working. What am i doing wrong?
$ grep CRON /var/log/syslog
Nov 28 15:20:01 sun CRON[1768]: (sun) CMD (sleep(10);/var/tmp/myscript.sh)
Nov 28 15:20:01 sun CRON[1766]: (CRON) error (grandchild #1768 failed with exit status 2)
Nov 28 15:20:01 sun CRON[1766]: (CRON) info (No MTA installed, discarding output)Follow up:
$ vim /var/tmp/crontab.sh
* * * * * sleep 10; /var/tmp/myscript.sh>/dev/null 2>&1
$ tail -f /var/log/syslog | grep CRON
Nov 28 15:50:02 sun CRON[2301]: (sun) CMD (sleep 10; /var/tmp/myscript.sh>/dev/null 2>&1)
Nov 28 15:51:01 sun CRON[2312]: (sun) CMD (sleep 10; /var/tmp/myscript.sh>/dev/null 2>&1) 2 Answers
Actually, the best way to use crontab is by using crontab itself:
crontab -l # list current crontab entries
crontab -e # edit the cron table
As soon as you finish editing the crontab (via 'crontab -e'), it is activated, and will fire off whatever was set whenever it was set to fire off.
Note that the machine must be running for crontab to work. If you want something more flexible, you can look at anacron(8).
1sleep does not take the argument in parentheses (like in C), so it should be
* * * * * sleep 10; /var/tmp/myscript.shAlways test the commands in the system shell before feeding it to cron ;).