mhorrocks
asked on
Open a file in perl script only if modified in last x minutes
In the following script, I open a log file. What I need to do is only open the file if it has been modified or created in the last 15 minutes.
Reason: Log file gets overwritten at least 5 times a day and I don't want to open a log file from a previous session.
#!/usr/bin/perl
use strict;
my $log = '/u/tmp/ftpupload_te.log';
my $emails = "anyone\@domain.com";
my $subject = "TECO FTP Upload Error";
my $subject1 = "TECO FTP Upload Success";
my $string1 = "File successfully transferred";
my $found;
open(LOG, ">$log");
open (FILE, "</u/tmp/mwh.log") || die "Cannot open file";
while(<FILE>)
{
$found ||=/$string1/
}
unless($found){print LOG "FTP Upload Error\n";}
unless($found){my $ret = `cat "/u/tmp/ftpupload_te.log" | mail -s "$subject" "$emails"`;}
close FILE;
close LOG;
exit(0);
Reason: Log file gets overwritten at least 5 times a day and I don't want to open a log file from a previous session.
#!/usr/bin/perl
use strict;
my $log = '/u/tmp/ftpupload_te.log';
my $emails = "anyone\@domain.com";
my $subject = "TECO FTP Upload Error";
my $subject1 = "TECO FTP Upload Success";
my $string1 = "File successfully transferred";
my $found;
open(LOG, ">$log");
open (FILE, "</u/tmp/mwh.log") || die "Cannot open file";
while(<FILE>)
{
$found ||=/$string1/
}
unless($found){print LOG "FTP Upload Error\n";}
unless($found){my $ret = `cat "/u/tmp/ftpupload_te.log" | mail -s "$subject" "$emails"`;}
close FILE;
close LOG;
exit(0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.