run the script on every 31st of month.....

Hello expert,

I need a logic code {don't want to schedule into crontab} which can run some of my code on 31st of Jan, March, Mya, Aug, Oct, Dec.....

Ex:

if [date "+%b %d, %Y" -eq Oct 24, 2011] then
echo "success"
fi

Please help me in achieving this

Thanks

day=`date +%d`
month="Jan, March, May, Aug, Oct, Dec"
echo $month | grep `date +%b`
[ $? -eq 0 -a "$day" -eq 31 ] && sh mycode.sh || echo "Not matching"

You can specify the format the date command outputs man date from this you can see that date +%d qill return the day of the month.

So you could use something like the following

if [ $(date +%d) -eq 31] ; then
   #call your script
fi

put in cronjob

0 10 31 * * * your_script