[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

cron bash date



Hello,

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.

The problem is that I want the month to reflect the previous month.

MON=$((`date +%m`-1))

This will work for every month except January where instead of getting 12
I get 0.  2 questions

1)  How can I modify the above line so that if `date *%m`-1 = 0 then MON=12
2)  I want the output to be 01-09 and not 1-9.  How can I change the format
    to add a zero?  +%m usually adds a zero but subtracting 1 causes the 0
    to be removed.

Lance







Reply to: