3.26.2006

cron deficiencies

I was told to make a process run the first day of every month, but cron doesn't have the "smarts" to do it.  I found the following solution to be adequate:

From: http://www.darklab.net/resources/hpux-mailinglist/0715.html

DO SOMETHING ON THE LAST DAY OF A MONTH
 
Unfortunately, cron does not give us a simple way to say
'run this on the last day of month'. Fiddling with the
different length months, leap years, y2k bugs and so on is
messy. Here's a simple solution that gives all the dirty
work to some well tested utility. The idea is to check whether
*tomorrow* is the first day of a month.
 
Solution 1 (using date, change MET to your local time zone)
 
#!/bin/sh
if test `TZ=MET-24 date +%d` = 1; then
   # today is the last day of month
fi
 
You can call this script from cron, say with a crontab of
4 2 28-31 * * /path/to/your/script

No comments: