CentOS 5.3

I am using crontab for the first time. However, I can't seem to get a simple script file to run.

Here is my crontab file:

50 17 * * * /home/dev_user/test_script.sh

It was scheduled to go off at 17:50, but it didn't work.

My script file test_script.sh

touch myfile.txt

The script files run ok when I execute it.

I have also restart crond:

/etc/init.d/crond restart

Many thanks for any suggestions,

link|improve this question

Is crond running? Do other cronjobs work? Other cronjobs under your account? – symcbean Oct 8 '10 at 11:29
1  
might be obvious, but check the time and date of the machine :-). – The Unix Janitor Oct 8 '10 at 12:27
@user37899, I forgot all about this. I had ssh into a terminal and I didn't check the date. I was using the time on my development machine. Thanks – ant2009 Oct 9 '10 at 2:21
feedback

4 Answers

up vote 2 down vote accepted

Is it executable?
Add this on top of your script:

#!/bin/sh

-edit-
Also, it might have ran, but not in a directory you expected it to (depending in which crontab you added this).
Change the touch to a absolute file like /tmp/myfile.txt

link|improve this answer
feedback

also try to debug via log file (/var/log/crond ... or something like that)

Based on faker's answer, how do you execute the script ? "sh script " or "./script" ?

link|improve this answer
feedback

You forgot to put the user in charge of running it before the path of the script.

Your line should be:

50 17 * * * dev_user /home/dev_user/test_script.sh

A little tip if you want to put it in one of the /etc/cron.* folder (hourly, daily, weekly or monthly), make sure you remove the extension .sh run-parts, the program in charge of executing the scripts, do not run scripts that contain an extension. take a look at the man page for more information. you can list the scripts that will be run using the --test argument of run-parts, as follow

$ run-parts --test /etc/cron.weekly/
/etc/cron.weekly//apt-xapian-index
/etc/cron.weekly//man-db
link|improve this answer
feedback

Do what the other answers suggested and also check, that you have a newline at the end of your crontab. (Required e.g. by the original vixie cron)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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