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.

use strict;

my $log = '/u/tmp/ftpupload_te.log';
my $emails = "anyone\";
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";

        $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;

Who is Participating?
ozoConnect With a Mentor Commented:
die "file not modified in the last 15 minutes" unless  -M "/u/tmp/mwh.log" < 15/(60*24);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.