On 5/2/07, Rob Dixon <[EMAIL PROTECTED]> wrote:
Chris E. Rempola wrote:
> Hi All:
>
> Could someone point me in the right direction to write out a simple Perl
> script to check for old files in a particular directory that are older
> than 20 mins. Is there a module to grab current timestamp? Thanks.
Check out
perldoc -f -x
and look at the -M option. It gives the age of the file in days in
floating point, so if its greater than 20/(24*60) your file is older than
twenty minutes.
HTH,
Rob
Not quite. -M reports "Script start time minus file modification time,
in days." To put it another way, -M reports how old the file was when
the script started running. Or more appropriately, how old the file
would have been when the script started running, assuming its current
mtime. That's not the same thing as how old the file is when the test
is executed.
For short-lived scripts, the difference is mainly a technicalityFor
long-running programs, though, -M's behavior has serious consequences.
-M on its own is useless in, say, a daemon that runs for days or
months--if you're lucky--or even in a program that just takes a while
to process all its data. The math to correct for running time is
complicated by -M returning fractional days. To use -M effectively,
you need to do something like:
my $minutes = 20;
if ( (-M "file") + ((time - $^T) / (24 * 60 * 60)) >
$limit_minutes/(24*60) )
{ do something }
Usually it's easier to just use the mtime from stat():
if (time - (stat "file")[9] > $minutes * 60)
{ do something }
Best,
-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org
values of β will give rise to dom!