Ok try this:
#!/bin/ksh
### STATIC INFO ###
refdatey=1970
refdatem=1
refdated=1
chkdatey=2002
###################
function timetosec {
hrtse=$(($chkdateh*3600))
mitse=$(($chkdatem*60))
totse=$(($hrtse+$mitse))
totaldays
}
function totaldays {
yrdiff=$(($chkdatey-$refdatey))
yrtda=$(($yrdiff*365))
pttda=$(($yrtda+$chkdated))
modays
fitda=$(($pttda+$dta))
daystosec
}
function daystosec {
datse=$(($fitda*24*60*60))
febextda
}
function febextda {
lepyrs=$(($yrdiff/4))
febadd=$(($lepyrs*24*60*60))
totalsec
}
function totalsec {
totalseconds=$(($datse+$totse+$febadd))
}
function modays {
case $chkdatemo in
Jan)
dta=0
;;
Feb)
dta=31
;;
Mar)
dta=59
;;
Apr)
dta=90
;;
May)
dta=120
;;
Jun)
dta=151
;;
Jul)
dta=181
;;
Aug)
dta=212
;;
Sep)
dta=243
;;
Oct)
dta=273
;;
Nov)
dta=304
;;
Dec)
dta=334
;;
esac
}
list=`ls`
for var in $list;do
chkdatemo=`ls -l $var | awk '{print $6}'`
chkdated=`ls -l $var | awk '{print $7}'`
chkdateh=`ls -l $var | awk '{print $8}' | awk -F : '{print $1}'`
chkdatem=`ls -l $var | awk '{print $8}' | awk -F : '{print $2}'`
timetosec
echo "$var - $totalseconds" >> secondsoutput
done
This works fine for me. It takes the list of files in, then goes through the list, picking out what it needs (date/time) then processes that info through the function, then dumps the results into a file (secondsoutput).
This one also adjusts and adds seconds on for leap years.