From owner-freebsd-questions@FreeBSD.ORG Wed Dec 27 16:08:57 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4ED8616A617 for ; Wed, 27 Dec 2006 16:08:57 +0000 (UTC) (envelope-from wash@wananchi.com) Received: from ns2.wananchi.com (ns2.wananchi.com [62.8.64.4]) by mx1.freebsd.org (Postfix) with ESMTP id 85CD613C475 for ; Wed, 27 Dec 2006 16:08:56 +0000 (UTC) (envelope-from wash@wananchi.com) Received: from wash by ns2.wananchi.com with local (Exim 4.64 #0 (FreeBSD 4.11-STABLE)) id 1Gzb5i-000Nea-1i by authid for ; Wed, 27 Dec 2006 18:53:18 +0300 Date: Wed, 27 Dec 2006 18:53:17 +0300 From: Odhiambo Washington To: freebsd-questions@freebsd.org Message-ID: <20061227155317.GC95520@ns2.wananchi.com> Mail-Followup-To: Odhiambo Washington , freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Disclaimer: Any views expressed in this message, where not explicitly attributed otherwise, are mine alone!. X-Mailer: Mutt 1.5.13 (2006-08-11) X-Designation: Systems Administrator, Wananchi Online Ltd. X-Location: Nairobi, KE, East Africa. User-Agent: Mutt/1.5.13 (2006-08-11) Subject: Calculate the time of last modification of a file X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Dec 2006 16:08:57 -0000 Hiya, I hope you had a merry Christmas ;) I am trying to determine the time of last modification of a file, on FreeBSD. The following code achieves the same on Linux: # AGE = (current time) - (time of last modification of "$FILE") # please check your systems 'stat' command! AGE=$(($(date +%s) - $(stat -c '%Y' "$FILE"))) test $AGE -lt $DELAY && { echo -n yes exit 0 } Here is the whole bash script, just so that everything is clear: #!/usr/local/bin/bash test -t 0 && trap "echo" EXIT NAME="$1"; shift DELAY="${1:-600}"; shift BASE="${1:-/var/run/greydata}"; shift NAME=${NAME//.//} DIR=$BASE/${NAME%/*} FILE=$DIR/${NAME##*/} test -d "$DIR" || mkdir -p "$DIR" test -f "$FILE" || { > "$FILE" echo -n yes exit 0 } # AGE = (current time) - (time of last modification of "$FILE") # please check your systems 'stat' command! AGE=$(($(date +%s) - $(stat -c '%Y' "$FILE"))) test $AGE -lt $DELAY && { echo -n yes exit 0 } read <"$FILE" echo -n no exit 0 The `stat -c` is illegal for FreeBSD. However I don't seem to understand clearly what the man page for stat is telling me, to enable me make this work. -Wash http://www.netmeister.org/news/learn2quote.html DISCLAIMER: See http://www.wananchi.com/bms/terms.php -- +======================================================================+ |\ _,,,---,,_ | Odhiambo Washington Zzz /,`.-'`' -. ;-;;,_ | Wananchi Online Ltd. www.wananchi.com |,4- ) )-,_. ,\ ( `'-'| Tel: +254 20 313985-9 +254 20 313922 '---''(_/--' `-'\_) | GSM: +254 722 743223 +254 733 744121 +======================================================================+ What is mind? No matter. What is matter? Never mind. -- Thomas Hewitt Key, 1799-1875