Listing 14: yearago.sh
:
#######################################################
# yearago.sh - this script returns the decimal value for
# a 'year ago' in UNIX stat time. first it creates a
# temp file in order to read the stat record and get
# today's time, then it subtracts 3,153,600 seconds from
# that amount and echos the value. 3,153,600 is the
# number of seconds in a year.
# * 60 seconds in minute
# * 60 minutes in an hour
# * 24 hours in a day
# * 365 days a year
#---------
# 31,536,000
# create temp file
fn=/tmp/tmp_$$ ; > $fn
# call stat to return the modification time in decimal
# form
x=`stat -M $fn`
# remove temp file
rm -f $fn
# subtract a year's worth of seconds to generate the
# UNIX time it would have been a year ago.
x=`expr $x - 31536000`
# display the value
echo $x
# uncomment the following line to see the time and date
# for a year ago.
# ctime $x
exit 0
|