I need to run a specific command for a bunch of dates. To that end, I wrote a simple script that will loop through dates, formatted as the command will expect them using the date command:
startdate=`/bin/date --date="January 22 2011" +%e-%b-%Y`
enddate=`/bin/date --date="7-Nov-2011" +%e-%b-%Y`
echo "Start Date: $startdate"
echo "End Date: $enddate"
sleep 5
incdate="$startdate"
until [ "$incdate" == "$enddate" ]
do
echo "$incdate"
incdate=`/bin/date --date="$incdate 1 day" +%e-%b-%Y`
done
exit
If I set enddate to “6-Nov-2011” the script will stop as expected after printing 5-Nov-2011. However If i set enddate to “7-Nov-2011” as above, the script will print out “6-Nov-2011” forever. I can’t seem to figure out why…any ideas?
Thank You.
I think I figured out the problem – due to daylight savings time, incrementing 6-Nov-2011 by one day results in 6-Nov-2011 23:00:00 instead of 7-Nov-2011! Suppose I can put in an “if” for this special case.