Re: Calculate the time of last modification of a file

2006-12-28 Thread Odhiambo Washington
* On 27/12/06 10:54 -0600, Dan Nelson wrote:
| In the last episode (Dec 27), Odhiambo Washington said:
| > 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
| > }
| 
| You can use "stat -f '%m' $FILE", which is identical to Linux's 
| "stat -c '%Y' $FILE" .

Bang!

Thank you so much, Dan!
 

Best regards,
Odhiambo Washington
Systems Admin,
Wananchi Online Ltd.

Voted ISP of the Year 2006
Computer Society of Kenya Annual Awards
30Th Nov., 2006 ­ Panari Hotel, Nairobi


DISCLAIMER: See http://www.wananchi.com/bms/terms.php
--+-
 Odhiambo WASHINGTON. WANANCHI ONLINE LTD (Nairobi, KE)
 http://www.wananchi.com/email/ . 1ere Etage, Laptrust Plaza, Loita St.,
 Mobile: (+254) 722 743 223 . # 10286, 00100 NAIROBI
--+-
``It is always the best policy to speak the truth --
  unless, of course, you are an exceptionally good liar.'' (Jerome K Jerome)
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Calculate the time of last modification of a file

2006-12-27 Thread Dan Nelson
In the last episode (Dec 27), Odhiambo Washington said:
> 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
> }

You can use "stat -f '%m' $FILE", which is identical to Linux's 
"stat -c '%Y' $FILE" .

-- 
Dan Nelson
[EMAIL PROTECTED]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Calculate the time of last modification of a file

2006-12-27 Thread N.J. Mann
On Wednesday, 27 December, 2006 at 18:53:17 +0300, Odhiambo Washington wrote:
> 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
> }

I *think* what you are looking for is:

  stat -f '%Sm' -t '%s'

There is probably a much easier way to do that, but I couldn't find it
in the five minutes I had to spare.  :-)


Cheers,
   Nick.
-- 
Please do not CC me on replies, I read the list and don't need the dupes.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Calculate the time of last modification of a file

2006-12-27 Thread Odhiambo Washington
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<[EMAIL PROTECTED]>
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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"