in reply to Re^3: ignore list of files using readdir function
in thread ignore list of files using readdir function
You are right, it takes almost 15 minute which is too much
below is complete code.#! /usr/bin/perl use strict; use Math::BigFloat; Math::BigFloat->precision(0); sub GetINDirFiles { my ($path) = @_; opendir DIR, $path or die $!; my @files = readdir DIR; my @files = grep {!/\_ACK_/} readdir DIR; closedir DIR; return(@files); } sub GetOUTDirFiles { my ($path) = @_; opendir DIR, $path or die $!; my @files = readdir DIR; my @files = grep {/\_ACK.xml$/} readdir DIR; closedir DIR; return(@files); } # Main my $inpath = "/AAA/BBB/CCC/IN"; my $outpath = "/AAA/BBB/CCC/OUT"; 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 foreach my $infile (@infiles) { $infile =~ s/(.*)$insuffix/$1/g; # remove suffix to do co +mparation # Added by me foreach my $outfile (@outfiles) { $outfile =~ s/(.*)$outsuffix/$1/g; # remove suffix t +o do comparation if ($outfile eq $infile){ push (@delindex, $index); # get list of st +rings to be removed from array } } $index += 1; } delete @infiles[@delindex]; # remove strings my $currenttime = time; # get current time from system (epoch t +ime) foreach my $file (@infiles) { next unless (-f "$inpath/$file$insuffix"); # ignore directo +ries # INSERT SUFFIX AGAIN ($insuffix) my $mtime = (stat "$inpath/$file$insuffix" )[9]; # get mt +ime from file (epoch time) # INSERT SUFFIX AGAIN ($insuffix) my $diff = ($currenttime - $mtime); if ($diff > $timethreshold) { print "\n - file " . $file . $insuffix . " in " . $inpa +th . " directory was created at more than " . Math::BigFloat->new($d +iff / 60) . " minutes."; # INSERT SUFFIX AGAIN ($insuffix) # PUT THE ACTION THAT YOU WANT DO HERE!!! } }
i need to do it on regular interval like 5 minute or 15 minute, using an tool i use. so it really does not make sense if i check the files which i have already checked and i would not mind if this completes in minute or less then this but 15 minute is really too much
kindly assist
-KAKA-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: ignore list of files using readdir function
by hdb (Monsignor) on Jul 23, 2013 at 09:07 UTC | |
|
Re^5: ignore list of files using readdir function
by mtmcc (Hermit) on Jul 23, 2013 at 10:30 UTC | |
by kaka_2 (Sexton) on Jul 23, 2013 at 10:45 UTC | |
by mtmcc (Hermit) on Jul 23, 2013 at 12:13 UTC | |
by poj (Abbot) on Jul 23, 2013 at 12:37 UTC | |
by Anonymous Monk on Jul 23, 2013 at 10:51 UTC | |
by kaka_2 (Sexton) on Jul 23, 2013 at 11:04 UTC |