Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.sh

Now 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)
share|improve this question

2 Answers 2

up vote 2 down vote accepted

sleep does not take the argument in parentheses (like in C), so it should be

* * * * * sleep 10; /var/tmp/myscript.sh

Always test the commands in the system shell before feeding it to cron ;).

share|improve this answer
    
Thanks, edited in my follow up. –  YumYumYum Nov 28 '11 at 14:51
    
Note also that cron reports the output ( which in this case would have been an error message telling you what you did wrong ) via email, so you should install a mail server such as postfix and check your local mail. –  psusi Nov 28 '11 at 15:10

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).

share|improve this answer
    
i use BASH to create crontab files, in such case you need to write your crontab informations in a file and the reload them using that file path. Thanks anyway! –  YumYumYum Nov 28 '11 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.