Test Crontab

Is there a way i can test my crontab to see if it is working?
Who is Participating?
joolsConnect With a Mentor Commented:
most errors with scripts running under crontab are related around paths, for example, typing ifconfig on the command line will work because the path to the ifconfig program is in your environment, in cron this is different and it's usually best to specify the full paths for each command, to check to see if it's running, you aschedule a job and look at the errors (usually mailed to the root user or the MAILTO user in the crontab file).
woolmilkporcConnect With a Mentor Commented:
No, not really.

"crontab" performs a syntax check on its own, so the general format as well as the time/date specifications should be formally correct.

Cron just starts (or tries to start) the specified programs/scripts using sh, according to these time/date specifications.
It doesn't care whether these executables exist or do the right things.

Anything sent to stdout/stderr by these programs will be mailed to the owner of the crontab,
and cron also writes a log of its activities. The location of the log is OS dependent, mostly /var/log/cron or the like.
Kerem ERSOYConnect With a Mentor PresidentCommented:
You can create a cron task and see if it works.

For this run cron -e for the user who you want to run the task. and just do run tish command

* * * * * echo "This is a cron task"

Open in new window

This works for most distros but to get it work in RedHAT and derivatives such as CentOS etc. you'd rather edit /etc/crontab and add this line there instead


save exit and wait for the email to the relaed user.
tel2Connect With a Mentor Commented:
Or if you want to test without email, you could add something like this to your crontab:
    * * * * * date >/tmp/date.out 2>&1
Then wait a minute and check to see if there's a timestamp (or error) in that file.  Remember to delete the above from the crontab when you've finished the test.

I haven't seen a system where KeremE's suggestion of:
    cron -e
edits the crontab.  From my experience it is usually:
    crontab -e
g3nu1n3Connect With a Mentor Commented:
The logs for cron should be in /var/log/cron

You can run grep -i "whatyouarelookingfor" /var/log/cron

So say you have a true multi-user system where all the users have their own /home/user directory. You can run grep -i user /var/log cron

If that is not feasible, you can run grep -i "nameofscriptfile" /var/log/cron - i.e. grep -i myfile.php /var/log/cron

9x out of 10, the issue is not cron not running the job but the script failing. This can be because of additional flags needed for the binary that processes the script, or having to call that binary explicitly. Or just the fact that the script is coded improperly.

php -q /home/user/myphpscript.php
/usr/local/bin/php -q /home/user/myphpscript.php
/usr/local/bin/php /home/user/myphpscript.php

perl /home/user/myperl.pl

/usr/bin/GET http://domain.com/path/to/script.php
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.