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

Re: howto tell cron run last day of month



Hi,

On Tue, 17 Oct 2000, Jaume Teixi wrote:
> I run a cron script 27-31
> then inside the script i need to check if it this last day of month
> 
> how to check this ?

--<snip>--
#!/bin/sh

MONTH=`date +%m`
DAY=`date +%d`

case "$MONTH" in
    2)
        DAYS=28
        ;;
    4|6|9|11)
	DAYS=30
	;;
    1|3|5|7|8|10|12)
	DAYS=31
	;;
esac

if [ $DAYS = $DAY ]; then
    echo "Last day of Month"
else
    echo "$((DAYS-DAY)) days until next month"
fi
--<snap>--

However, this script does not look if we have a leap year.

     Ciao,
         Timo<t_benk@gmx.de>
--

    .-'~~~-.	   
   .'o oOOOo`.      | Timo Benk	
  ;~~~-.oOo   o`.   | Germany
   `. \ ~-.  oOOo.  | Fax/Voicemail:    +49891488214215
     `.; / ~.  OO:  | 
     .'  ;-- `.o.'  | 
    ,' ; ~~--'~     | [ASCII stolen from Mescalito Ted]
    ;  ;            |  
_\\;_\\//_          



Reply to: