6

I'd like to know how I can check to see if my cronjob will run at the specified time I set it at. Is there anyway I can test this without having to wait for that time?

Here are my crontab -l results:

root@work:~$ crontab -l
3 */23 * * * /opt/lampp/bin/php /opt/lampp/htdocs/site/cron/my_script.php > /dev/null

If I did the values right, will my cronjob run at exactly 11pm every night and log any output to /dev/null for cleanliness?

Thanks.

  • Great question. Additionally, I would like to know if it's possible to get a report of Cron on what actions it will perform doing for the next [defined] period of time. – gertvdijk Sep 18 '12 at 21:53
6

The only way to be sure is to let it run and inspect the results. You can modify your command to log the output somewhere and inspect that, or let it email you the output.

You could add another identical line which runs the command within 5 minutes or so, for debugging. eg. If it's 3:13 pm right now, I might add this line to test the command after 3 minutes from now:

# Run at 15:16
16 15 * * * /opt/lampp/bin/php /opt/lampp/htdocs/site/cron/my_script.php > /dev/null

BTW. To run at 11 PM every night, you probably want this instead; I have also redirected stderr to stdout (2>&1) to ensure that all output goes to /dev/null:

# At minute 0 of hour 23 on every day, every month, every day of the week:
0 23 * * * /opt/lampp/bin/php /opt/lampp/htdocs/site/cron/my_script.php > /dev/null 2>&1
  • Thank you for the great answer. Thanks to everyone else in this question for the helpful and positive comments/answers! – user1062058 Sep 18 '12 at 23:48
3

I guess the simplest option is to set your cron job at an earlier time, say 5 minutes from now and see if the job worked. Additionally it is good form to have your cron run log into a dated file. That way you can see #1 that it did run, and #2 it ran correctly.

Make sure your system time is correct as well.

3

As an addition to the other good answers, you can sanity check cron settings with online test pages:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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