http://www.perlmonks.org?node_id=789020

John007 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I need to find the file created in last minute. I have sun solaris system which creates files called log_yy_mm_dd_hh_mm_ss.txt in a directory called mydir. I need to check for the file created in last minute and pull some data compare against set values and generate output.
I am having issue in identifying the last minute file. I can read files of that dir and compare with current time using localtime parameter as shown below but problem exists when time changes from ex. 7:59 to 8:00 or day changes at midnight i.e. script is non functional for a 1 minute period. I am looking for any unix commands/script or perl script whcih can give me last minute file. Though my file does have time stamp with its name. Thanks in advance
#!/usr/bin/perl use Data::Dumper; use Time::localtime; $year = (localtime -> year) + (1900); $mon = (localtime -> mon) + (1); $mday = localtime -> mday; $hour = localtime -> hour; $min = (localtime -> min) ; opendir (DIR, $directory) or die $!; while (my $file = readdir(DIR)) { if ($file =~ /^\w{10,16}(.txt)$/i ) { $filename = $1; if (($year == $fyear) && ($mon == $fmon) && ($mday == $fmday) && ($ho +ur == $fhour) && ($min == ($fmin + 1))) { $myfile = $filename; } } }