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;
}
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.