How to Test a New Cron Script

cronlinuxtesttesting

I'm running on a couple of different Linux distros (Fedora 11, CentOS 5 and SuSE 10.2) and often run into a problem where a new script that I want to run as a cron job works fine when called direct from the command line, but fails when called from cron due to slight variations in the PATH or other required environment variables.

Is there a way I can test run an individual script as if it's being run from cron, without having to run the entire crontab or use run-parts to run the entire cron.daily/ .hourly etc. directory ? I guess I could temporarily edit my crontab to run the script in the next couple of minutes, but I'd rather have a more standalone solution so that I don't risk messing up the crontab.

Best Answer

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.