Linux – How to ensure the cronjob will run at specified time

cronlinux

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.

Best Answer

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
Related Question