You need to do something on a daily with a file in a directory named yyyy-mm-dd.txt (year-month-day.txt).
That's easy enough:
#!/bin/ksh
# just get the current date
today="`date +%Y-%m-%d`"
filename="${today}.txt"
echo $filename
Oops, you need the file from yesterday. Not so simple any more as the unix date command just sets or prints the date.
Let's do some of the usual date math (month ends, leap years, etc.).
#!/bin/ksh
# default is one to travel back in time to yesterday
daystogoback="1"
# to be a little dynamic, we can use an argument to go back n days.
if [ $# -eq "1" ]; then
daystogoback="$1"
fi
# get the current year month and day
nowy=`date +%Y`
nowm=`date +%m`
nowd=`date +%d`
# get rid of the month's possible leading zero
nowm=`echo $nowm*1|bc`
# if today's day is greater than the number of days to go back
# we really can just take the shortcut and subtract the days to go back
# because we will stay in the current month and nothing fancy is needed
if test $nowd -gt $daystogoback
then
nowd=`echo $nowd-$daystogoback|bc`
else
# if we are in January, we have to go to the previous year
# and set the month to December
# else we can just subtract the month
if test $nowm -eq "1"
then
nowy=`echo $nowy-1|bc`
nowm="12"
else
nowm=`echo $nowm-1|bc`
fi
# now we can calculate the day, but first we have to see
# how many days in the month...
# we default to 31 and do nothing more for the months with 31 days
# we have to check for February and then for a leap year (28/29)
# the rest of the months will have 30 days
newd="31"
case "$nowm" in
"1") ;;
"3") ;;
"5") ;;
"7") ;;
"8") ;;
"10") ;;
"12") ;;
"2") if test "0" -eq "`echo $nowy%4|bc`"
then
newd="29"
else
newd="28"
fi ;;
*) newd="30" ;;
esac
# subtract the current day from the days to go back
# and then from the total days in the month
nowd="`echo $daystogoback-$nowd|bc`"
nowd="`echo $newd-$nowd|bc`"
fi
# now we just do some formatting for the month and day
if test $nowm -lt "10"
then
nowm="0$nowm";
fi
if test $nowd -lt "10"
then
nowd="0$nowd";
fi
# our new date
filedate="$nowy-$nowm-$nowd"
# and the file we need to access...
filename="${filedate}.txt"
echo $filename
Always fun playing with dates.
References:
KSH script BASICS
Wikipedia: Korn shell