How can I test a new cron script?

From google search on path in crontab

root@pingu # cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

You basically want to set the PATH and then not have to worry about the variations. Also, the quick test is to run your script via SSH on all your boxes using the same environment variables.


If I'm running an individually-scheduled cron job (a separate line in crontab) I'll schedule it for every minute or every other minute as I'm testing it. Once it's tested out, I'll edit the crontab line so it runs on the frequency I desire.

As a side-note, if I want to test that cron itself is working properly, and emailing the results to the correct address (VERY important) I'll add the following line to my /etc/crontab:

 * * * * * root ls /doesnotexistfoobar

Runs every minute, and tries to do an ls on a directory that doesn't exist. Should email a failure message every minute. I comment the line out when I've got it working.

Back to your question: You probably don't want to modify the existing cron job to run often, both because there's a chance of forgetting to change it back, and because running your cron.hourly, cron.daily, or cron.whatever often could have side-effects, depending on what you've got in there. To ensure that you're running the script in the same environment that it's going to be in when called from cron, I'd recommend modifying my "ls" trick above:

Add a line to your crontab to run the script directly:

 * * * * * root /etc/cron.hourly/customscript

That way you can run it as often as you need to test it.