shell: sh
system: SCO unix 5.05 (openserver)
I have a script that tests the date then downloads a specific file based on the date via ftp.
My problem is that 0's in the date get dropped. ie january 01 would become 1
Date code came from: http://unix.about.com/library/weekly/aa070901a.htm
Part of my script
month=`date +%m`
day=`date +%d`
year=`date +%Y`
month=`expr $month + 0`
day=`expr $day - 1`
if [ $day -eq 0 ]; then
month=`expr $month - 1`
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
;;
esac
fi
fi
Ftp stuff goes here
To download the file i need January to = 01 and not 1. I can make 18 if statements to change 1-9 for $day and $month to place a 0 in front of them, but there has got to be a better way.
Can anyone help with this?
Thank you