Does this do what you want?:
#! /usr/bin/perl
use strict;
use Math::BigFloat;
Math::BigFloat->precision(0);
sub GetINDirFiles {
my @files;
my ($path) = $_[0];
opendir (my $directory, $path) or die $!;
while(readdir $directory)
{
push (@files, $_) unless (($_ =~ m/_ACK_/) || ($_ =~ m
+/^\./));
}
closedir $directory;
return(@files);
}
sub GetOUTDirFiles {
my @files;
my ($path) = $_[0];
opendir (my $directory, $path) or die $!;
while(readdir $directory)
{
unless ($_ =~ m/^\./)
{
push (@files, $_) if $_ =~ m/_ACK.xml/;
}
}
closedir $directory;
return(@files);
}
# Main
my @range;
my $inpath = "./IN/";
my $outpath = "./INACK/";
my $outsuffix = "_ACK.xml";
my $insuffix = ".xml"; # Added by me
my $timethreshold = 900; # set time threshold in seconds (900 se
+conds equal 15 minutes)
my @delindex;
my @infiles = &GetINDirFiles($inpath);
my @outfiles = &GetOUTDirFiles($outpath);
my $index = 0; # index used to get string position in array
my $count = @infiles;
for (my $x = 0; $x < $count; $x+= 1)
{
my $name = $infiles[$x];
$name =~ s/$insuffix//;
for (@outfiles)
{
if ($_ =~ m/$name/)
{
push (@range, $x)
}
}
}
my $rangeCount = @range;
for (my $x = 0; $x < $count; $x+= 1)
{
splice(@infiles, $range[$x], 1);
}
# remove strings
my $currenttime = time;
# get current time from system (epoch time)
foreach my $file (@infiles)
{
my $fileForTime = "$inpath"."$file";
my $mtime = ( stat $fileForTime )[9];
my $diff = ($currenttime - $mtime);
# ignore directories # INSERT SUFFIX AGAIN ($insuffix)
# get mtime from file (epoch time) # INSERT SUFFIX AGAI
+N ($insuffix)
if ($diff > $timethreshold)
{
print "\n - file " . $file . " in " . $inpath . " direc
+tory was created at more than " . Math::BigFloat->new($diff / 60) .
+" minutes."; # INSERT SUFFIX AGAIN ($insuffix)
# PUT THE ACTION THAT YOU WANT DO HERE!!!
}
}
NOTE: Change the pathnames! |