URGENT HELP NEEDED--compare current date file with previous day

URGENT HELP NEEDED--compare current date file with previous day

Post by Shahria » Thu, 28 Sep 2006 04:24:56


Hi All,

I am new in perl. I have report files which generate in particular
location day by day. I need to write a script to compare the current
date file with the previous day for first line. If there is a
difference it will generate email automatically to the users. The log
files with other few files generate in a folder which is named by date
(format: MM-DD-YY).

Some key points:

Location of the log files file:

/home/usr/09-26-06/log1.rpt and I need to compare with the previous
day: /home/usr/09-25-06/log1.rpt.... some thing like that.

The log.rpt file looks like:

PASS (P) 10
FAIL (F) 1.............................

I need to compare the second line. If the no. of FAIL changes then it
will send email automatically to the users.

Any help is appreciated.

Thanks.
 
 
 

URGENT HELP NEEDED--compare current date file with previous day

Post by usene » Thu, 28 Sep 2006 07:01:16


You reduce your chances of getting help when you shout how important it
is. It's really urgent only to you.


use Date::Manip;
my %log;
$log{$_} = sprintf("/home/usr/%s/log1.rpt",
UnixDate($_,'%m-%d-%y')
) for qw{today yesterday};

Now open and read $log{'today'} and compare line 2 with
$log{'yesterday'}. You may prefer to use Tie::File to simplify this.


You may be able to get by with a straight eq operation.

perldoc perlop

To be on the safe side, parse out the value with a regular expresion:

perldoc perlre



use Mail::Sendmail; #or one of the many other mail modules

--
David Filmer ( http://www.yqcomputer.com/ )

 
 
 

URGENT HELP NEEDED--compare current date file with previous day

Post by DJ Stunk » Thu, 28 Sep 2006 12:21:39


I really like your hash approach here. No need for the sprintf though:

my $format = '/home/usr/%m-%d-%y/log1.rpt';
my %log = map { $_ => UnixDate($_, $format) } qw{ today yesterday };

:)

-jp
 
 
 

URGENT HELP NEEDED--compare current date file with previous day

Post by usene » Thu, 28 Sep 2006 14:00:45


That's two cool tricks you've showed me in one day - I owe you a beer!

--
David Filmer ( http://www.yqcomputer.com/ )