I am writing a script to strip data from a log, strip last month and empty the log for the comming month. It works great at the moment, but during testing I decided to change the date to 12/31 and when I ran it, it did not find tomorrows date. Further testing revealed that no dbl digit month would pick up the next months date.
I am using "TZ=CST6CDT-24 date +%d" to list tomorrows date, ie...
# # date 07311300
Fri Jul 31 13:00:18 CDT 2009
# TZ=CST6CDT-24 date +%d
01
I can set the date to 0731 and it works fine, but if I do a month with dbl digits (10, 11, 12) it returns like below....
# date 10311300
Sat Oct 31 13:00:22 CDT 2009
# TZ=CST6CDT-24 date +%d
31
This works for every day except the last day of the month on dbl digit months.
Does anyone have an explanation?
Here is the actual script...
#! /bin/ksh
# TZ=CST+24 date +%Y-%m-%d (yesterday)
# TZ=CST-24 date +%Y-%m-%d (tomorrow)
day=$(date '+%d')
month=`TZ=CST6CDT+24 date +%m`
year=`TZ=CST6CDT+24 date +%Y`
if test `TZ=CST6CDT-24 date +%d` = 01; then
echo $month
echo $year
grep $month/[0-9][0-9]/$year /tmp/ftp.log > ftp.log.$year.$month
>ftp.log
fi
Thanks
Dave