We all write crontab jobs.   I tend to write really complicated ones, where each line in the crontab has multiple statements, for loops and while loops.  Which makes it moderately hard to figure out if it’s working.

So I created a simple little test script that reads the crontab, and then runs each line of the crontab separately, showing you what happens inside.   Could you have written this yourself in less time that it took you to google for and find this post?  Sure.  But sometimes it’s too early in the morning, the coffee maker is broken, and you want to just grab a working script.

#!/bin/bash
# $Id: crontab-test.sh 2771 2010-05-28 18:33:22Z bdobyns $

idx=0
#m h d m w cmd
if [ -z "$1" ] ; then
	echo "usage: $0 [crontabname]"
	exit
else
	cat "$1" | grep -v '^#' | grep -v ^MAILTO | while read m d h m w cmd
	do
		F=/tmp/$0.$$.$idx
		echo -n $cmd >$F
		if [ -s $F ] ; then
			bash -ex $F
		fi
		idx=$[ $idx + 1 ]
	done
fi

rm -rf /tmp/$0.*

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Both comments and pings are currently closed.