Date: Sat, 22 Jan 2000 16:06:03 +0100 (CET) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: freebsd-questions@FreeBSD.ORG, cjclark@home.com Subject: Re: sh(1) Messing with My Mind Message-ID: <200001221506.QAA14283@dorifer.heim3.tu-clausthal.de> In-Reply-To: <868r13$2gq9$1@atlantis.rz.tu-clausthal.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Crist J. Clark <cjc@cc942873-a.ewndsr1.nj.home.com> wrote in list.freebsd-questions:
> But since we're having so much fun with all of this, maybe I should
> try this one on all of you. Given Ben's code above, how would _you_
> determine how long ago $DATE was from the present time?
I'd first convert the date string to a time_t value. The
easiest way to accomplish that is probably to install GNU
date:
DATE="Fri 21 Jan 2000 00:15:59 GMT"
TIMET=`gdate -d "$DATE" +%s`
$TIMET will then contain the number 948413759. You can get
the current time (int time_t format) like this:
NOW=`date +%s`
This works both with GNU date and BSD date (but BSD date
doesn't support something like the -d option of GNU date
above, AFAIK).
Now it is easy to make claculations and comparisons with the
time_t values, using "awk" or "expr" or whatever you like,
e.g.:
ONE_DAY=86400 # 24 * 60 * 60
YESTERDAY=`expr $NOW - $ONE_DAY`
if [ $TIMET -lt $YESTERDAY ]; then
echo "previous backup is older than one day"
...
fi
You get the idea. :)
Regards
Oliver
--
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)
"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
(Terry Pratchett)
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001221506.QAA14283>
