cancel
Showing results for 
Search instead for 
Did you mean: 

check date

SOLVED
Go to solution
heaman1
Regular Advisor

check date

I would like to write a script as below , can advise what can i do .


if this month is Jan , May , July and today is last day of month ( 28th, 29th , 30th or 31th )

then do xxx

if this month is Feb , Mar , Aug and today is last day of month ( 28th, 29th , 30th or 31th )

then do yyy

end.




can advise how to write this script ? thx
6 REPLIES
Dennis Handly
Acclaimed Contributor
Solution

Re: check date

You can use Arturo's trick to find the last day of the month:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1158441

if [[ $(cal) = *$(date +%d) ]]; then # last day of month
case $(date $b) in
Jan|May|Jul) xxx;;
Feb|Mar|Aug) yyy;;
esac
fi
heaman1
Regular Advisor

Re: check date

thx reply,

I changed today as 31Dec and the script as below .

=================================
if [[ $(cal) = *$(date +%d) ]];
echo testing
case $(date $b) in
Jan|May|Jul) echo test1 ;;
Feb|Mar|Dec) echo test2 ;;

esac
fi
==================================

The output is "testing" only ,
I think it check today is last day , but do not recognize this month is Dec , can advise how to change it ? thx



F Verschuren
Esteemed Contributor

Re: check date

The folowing will work for most shells

case $(date |awk '{ print $2 } ' ) in
Jan|May|Jul) echo test1 ;;
Feb|Mar|Dec) echo test2 ;;
esac
Dennis Handly
Acclaimed Contributor

Re: check date

>The output is "testing" only, but do not recognize this month is Dec

Oops, a typo, $b vs %b:
if [[ $(cal) = *$(date +%d) ]]; then # last day of month
case $(date %b) in
Jan|May|Jul) test1;;
Feb|Mar|Aug) test2;;
esac
fi

>F Verschuren: The following will work for most shells

Why would you want to use awk(1) if date(1) will do the right thing, if you do it right. :-)

Dennis Handly
Acclaimed Contributor

Re: check date

Oops again, that should be:
case $(date +%b) in
heaman1
Regular Advisor

Re: check date

thx all .