Re: Crontab last days of the month..
On Wed, Apr 14, 2004 at 09:58:38AM -0600, s. keeling wrote:
> Incoming from Wayne Topa:
> > Rus Foster(rghf@fsck.me.uk) is reported to have said:
> > > Hi All,
> > > Couldn't find a decent answer to this in google but goes as follows
> > >
> > > If I have a cron job that is scheduled for the 31st of the month and the
> > > month we are in doesn't have 31 days would it be run on the last day of
> > > the month or not run at all?
> >
> > I bzip up all my mail at the end of the month and had the same
> > problem. I solved it by having the script run 1 minute after midnight
> > on the 1st of the month.
>
> Another way is to run it every day, but have the script figure out if
> it's the last day of the month, and exit if not. I have no idea where
> I found this, nor have I tested it extensively:
>
> days_in_month ()
> {
> dim_m=${1:-`date +%m`};
> dim_m=`monthnum $dim_m`;
> case ${dim_m#0} in
> 9 | 4 | 6 | 11)
> echo 30
> ;;
> 1 | 3 | 5 | 7 | 8 | 10 | 12)
> echo 31
> ;;
> 2)
> is_leap_year ${2:-`date +%Y`} && echo 29 || echo 28
> ;;
> esac
> }
if [ $(date -d tomorrow '+%m') -ne $(date '+%m') ]
then
echo 'today is the last day of the month'
fi
--
"Without private property, there is no meaningful economic
calculation, and without meaningful economic calculation,
there is only economic chaos." -- William Anderson
Rick Pasotto rick@niof.net http://www.niof.net
Reply to: