I have a case statement in place where at the beginning of the month if the file begins with the day "01" all of the files should revert to the previous day. For example....today is 050201. The files should then read 050131. For the first file, it is coming out 050131. The next file is coming out 051231 then the next 051131. Here is the code that I currently have in place. It looks like the first file comes out fine then the case statement looks at that file and bases the case off of it and that is why the dates are wrong. Any help would be greatly appreciated.
for file in `ls *.dly`
do
if [ ${day} = "01" ]
then
case "$month" in
01) oldday="31"
month="12";;
02) oldday="31"
month="01";;
03) if [ $julian = "060" ]
then
oldday=28
else
oldday=29
fi
month="02"
;;
04) oldday="31"
month="03";;
05) oldday="30"
month="04";;
06) oldday="31"
month="05";;
07) oldday="30"
month="06";;
08) oldday="31"
month="07";;
09) oldday="31"
month="08";;
10) oldday="30"
month="09";;
11) oldday="31"
month="10";;
12) oldday="30"
month="11";;
esac
else
oldday="`expr $day - 1|awk '{printf(\"%02i\", $1)}'`"
fi
f=$(echo "$file" | sed 's!......\.dly!!')
filename="${f}_${year}${month}${oldday}.dly"
cp -p ${colddir}/${file} ${colddir}/${filename}
cp -p ${colddir}/${filename} ${sentdir}
for file in `ls *.dly`
do
if [ ${day} = "01" ]
then
case "$month" in
01) oldday="31"
month="12";;
02) oldday="31"
month="01";;
03) if [ $julian = "060" ]
then
oldday=28
else
oldday=29
fi
month="02"
;;
04) oldday="31"
month="03";;
05) oldday="30"
month="04";;
06) oldday="31"
month="05";;
07) oldday="30"
month="06";;
08) oldday="31"
month="07";;
09) oldday="31"
month="08";;
10) oldday="30"
month="09";;
11) oldday="31"
month="10";;
12) oldday="30"
month="11";;
esac
else
oldday="`expr $day - 1|awk '{printf(\"%02i\", $1)}'`"
fi
f=$(echo "$file" | sed 's!......\.dly!!')
filename="${f}_${year}${month}${oldday}.dly"
cp -p ${colddir}/${file} ${colddir}/${filename}
cp -p ${colddir}/${filename} ${sentdir}