[NTLUG:Discuss] How to tell file1 is half an hour older than file2?
Paul Ingendorf
pauldy at wantek.net
Mon Apr 29 10:32:41 CDT 2002
I know you can do file1 -ol file2 but for time I'm pretty sure you would have to write your own function to tell for sure.
Just think it out logically it might take a bit of time but it isn't all that hard per se.
function returnTimeDiff {
echo some code here for file $1 and file $2
}
What I would recommend is turning the dates into a single number via whatever algorithm you like. I.E. year in seconds/minutes Same for month day and hour then add your minutes or seconds and subtract the two and check the difference.
The following should show you how easy it is. The following script requires sed, awk, and stat all GNU tools installed on most systems.
# ---------------------------------- Example -----------------------------------
# Author Paul Ingendorf
function returnYear {
echo $1 | awk -F\| {print'$6'}
}
function returnMonthNum {
month=`echo $1 | awk -F\| {print'$3'}`
case "$month" in
Jan)
echo 1
;;
Feb)
echo 2
;;
Mar)
echo 3
;;
Apr)
echo 4
;;
May)
echo 5
;;
Jun)
echo 6
;;
Jul)
echo 7
;;
Aug)
echo 8
;;
Sep)
echo 9
;;
Oct)
echo 10
;;
Nov)
echo 11
;;
Dec)
echo 12
;;
*)
echo 0
esac
}
function returnDay {
echo $1 | awk -F\| {print'$4'}
}
function returnHour {
echo $1 | awk -F\| {print'$5'} | awk -F: {print'$1'}
}
function returnMinute {
echo $1 | awk -F\| {print'$5'} | awk -F: {print'$2'}
}
function returnSecond {
echo $1 | awk -F\| {print'$5'} | awk -F: {print'$3'}
}
function returnTime {
let Time=`returnMonthNum $1`*24*60*60+`returnDay $1`*24*60*60+`returnHour $1`*60*60+`returnMinute $1`*60+`returnSecond $1`
echo $Time
}
let x=1
for modified in `stat $1 $2 | grep Modify | sed -e "s/ /|/g"`
do
export fileDate$x=$modified
let x=$x+1
done
let fileTime1=`returnTime $fileDate1`
let fileTime2=`returnTime $fileDate2`
let timeDiff=$fileTime2-$fileTime1
if test `returnYear $fileDate1` -gt `returnYear $fileDate2`
then echo older than 30
else
if test $timeDiff -gt 29
then echo older than 30
else echo not older than 30
fi
fi
# -------------------------------- End Example ----------------------------------
--
-->> mailto:pauldy at wantek.net
-->> http://www.wantek.net/
Running ....... Cos anything else would be a waste...
`:::' ....... ......
::: * `::. ::'
::: .:: .:.::. .:: .:: `::. :'
::: :: :: :: :: :: :::.
::: .::. .:: ::. `::::. .:' ::.
.:::.....................::' .::::..
-----Original Message-----
From: discuss-admin at ntlug.org [mailto:discuss-admin at ntlug.org]On Behalf
Of Sameer Khan
Sent: Saturday, April 27, 2002 1:51 PM
To: discuss at ntlug.org
Subject: [NTLUG:Discuss] How to tell file1 is half an hour older than
file2?
Hello,
Any ideas how one can go about doing above in
a ksh script (without GNU tools unfortunately)?
Thanks for your brain droppings!
Sameer
_______________________________________________
http://www.ntlug.org/mailman/listinfo/discuss
More information about the Discuss
mailing list