w****c 发帖数: 10 | 1 another question:
in shell script, how to compare date? for instance, give the
"19/Mar/2002:17:14:06", ask if this time is within a specified
time slot, for example, last 50 minutes? how could you implment
it?
thanks! Here are a lot of unix guru.really benefit from it. | s**i 发帖数: 30 | 2 you can use something like this to compare two time:
#!/bin/bash
E_NOTSAMEDAY=-197
E_PARAM_ERR=-198
if [ -z "$2" ]
then
exit $E_PARAM_ERR
fi
day1=`echo $1|cut -d: -f1`
hour1=`echo $1|cut -d: -f2`
min1=`echo $1|cut -d: -f3`
#sec1=`echo $1| cut -d: -f4`
day2=`echo $2|cut -d: -f1`
hour2=`echo $2|cut -d: -f2`
min2=`echo $2|cut -d: -f3`
#sec2=`echo $2| cut -d: -f4`
if [[ "$day1" != "$day2" ]]
then
exit $E_NOTSAMEDAY
fi
diffh=$((hour2-hour1))
diffm=$((min2-min1))
difft=$((diffh*60+diffm))
ech
【在 w****c 的大作中提到】 : another question: : in shell script, how to compare date? for instance, give the : "19/Mar/2002:17:14:06", ask if this time is within a specified : time slot, for example, last 50 minutes? how could you implment : it? : thanks! Here are a lot of unix guru.really benefit from it.
|
|