From owner-freebsd-questions Sat Jan 22 7: 6:12 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id CF15B15546 for ; Sat, 22 Jan 2000 07:06:07 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id QAA14283; Sat, 22 Jan 2000 16:06:03 +0100 (CET) (envelope-from olli) Date: Sat, 22 Jan 2000 16:06:03 +0100 (CET) Message-Id: <200001221506.QAA14283@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG, cjclark@home.com Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: sh(1) Messing with My Mind X-Newsgroups: list.freebsd-questions In-Reply-To: <868r13$2gq9$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Crist J. Clark 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