Hi All,
I know there has been a lot of things that have been written about date arithmetic, but perhaps I have missed something..
The following script takes the input from a file name fail.txt with the following format:
CLASSDB 20060328122808
CPPARMS 20060814222056
Where $1 is a file name and $2 is the creation timestamp.
I have attempted to calculate the age of the file from reading the timestamp($2)
heres the script i wrote
#!/usr/bin/ksh
cat fail.txt | while read line
do
created=`echo $line | awk '{print $2}' | sed "s/\(.\{4\}\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1\2\3/"` && name=`echo $line | awk '{print
$1}'`
today=`TZ=aaa date +%Y%m%d`
days_old=`echo $(($today - $created))`
echo "$name $created $days_old" >> test_fail.txt
done
if [ -e test_fail.txt ]
then
uuencode test_fail.txt test_fail.rtf | mailx -s "test" g2kaushi@hewitt.com
rm test_fail.txt
fi
I get the error ":more tokens expected at the row where 'days_old" is being calculated(which is a minor issue).
The issue that i am more concerened with is
the "days_old" variable calculation is failing if the file is from the previous month or year.
I work on Solaris 8 so a lot of date options or the GNU date are not available to me.
I am only looking for a way to convert the timestamp of the fail.txt($2) to no of days from today.
I apologize if this has been discussed earlier but I was not able to find any age related threads.
Thanks in advance.