Lance Hoffmeyer <[EMAIL PROTECTED]> writes:

> I am trying to run a bash script in cron.  I originally wanted
> it to run at 11:59pm on the last day of every month.  February
> will always cause problems because of leap years.  Therefore,
> I decided to run cron on the first day of every month using
> the @month parameter.

crontab(5) doesn't suggest a good way to do this, no.  So yeah,
running early (say, 12:03 AM) on the first of the month is easy:

  3 0 1 * * /usr/local/sbin/ourscript

> The problem is that I want the month to reflect the previous month.
>
> MON=$((`date +%m`-1))

How about:

  MON=`date -d yesterday +%m`

date(1) seems to think "yesterday" is exactly 24 hours ago, if you're
looking at other fields.  (Or maybe it's exactly a day ago; this makes
a difference around daylight savings.)

-- 
David Maze         [EMAIL PROTECTED]      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
        -- Abra Mitchell


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to