Jason Viloria <[EMAIL PROTECTED]> wrote:
> 
> Can someone help me plaease use perl to monitor the timestamp
> of a text file to alert me if it is more than 1 minute old and run 
> an external program if so? 
> 
> I suppose a simple script which runs in cron would do the job but
> maybe someone else has a better solution?
> 

This just wakes up every 5 seconds to check the file.

If you want, figure out how many seconds you have left 
before it could possibly expire, and sleep that long...


#!/usr/bin/perl
# see also perldoc -q daemon

my $file  = 'foo.txt';
my $cmd   = "echo File '$file' has expired.";
my $limit = 60; 

my $already = 0;

while (1) {
    my $mtime = (stat $file)[9];

    die "file '$file' not found." unless -f _;
    next if $mtime == $already;

    if (time - $mtime > $limit) {
        system($cmd) == 0 or
          warn "'$cmd' exited with status: ", $?>>8;
        $already = $mtime;
        next;
    } 
    $already = 0;
} 
continue { 
    sleep 5;
}


-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to