[Sderby] PERL again!
sderby@mailman.lug.org.uk
sderby at mailman.lug.org.uk
Mon Jan 13 10:52:01 2003
Mike
Have you had a chance to look at my previous email re PERL. Here is a rather
more considered response. You need to find a regular expression that detects
the end or your error message and insert it into the code below.
Andre
PS This code assumes that the legato file and the perl script are in the
same directory.
#!/usr/bin/perl -w
# script name:Legato.pl Extracts multiline error message
use strict;
use IO::Handle;
my $mylegatofile= "Name of backuplog"; #Legato backup file
my $myfailfile= "translog.log"; #log for recording backup errors
open BACKUPFILE, "< $mylegatofile" or die "Cannot open $mylegatofile: $!";
#open legato file for reading
open LOGFILE, ">> myfailfile" or die "Cannot open myfailfile: $!";
#open failiure log for appending
print LOGFILE "-"x80,"\n","Now processsing $mylegatofile\n";
my $tempmessage = "";
my $messagestartflag = "false"; #Flag switched to true when start of message
is detected
my $messagecompleteflag = "false"; #Flag switched to true when end of
message is detected
while (<BACKUPFILE>) {#Reads one line of the legato backup at a time
if(/^.*(?:Unsuccessful Save Sets)$.*/so){ #Regular Expression detects
start of message
$tempmessage= $1; #Capture start of error message
$messagestartflag = "true";
}
if($messagestartflag == "true" && $messagecompleteflag == "false"){
#Still within body of error message
$tempmessage .= $_; #Add new line read onto tempmessage
}
if(/^.*(?:Text which identifies end if message)$.*/so){ #Regular
Expression detects end of error message
$messagecompleteflag = "true"; #Capture start of error message
}
if($messagestartflag == "true" && $messagecompleteflag == "false"){
#Still within body of error message
print LOGFILE "$tempmessage\n";
$messagestartflag = "false";$messagecompleteflag = "false";
}
}
close BACKUPFILE;close LOGFILE;
----- Original Message -----
From: "Mini Mike" <hemstock@tiscali.co.uk>
To: <sderby@mailman.lug.org.uk>
Sent: Thursday, January 09, 2003 5:09 PM
Subject: [Sderby] PERL again!
> Hi all,
>
> I'm currently writing a PERL script to analyse log files from Legarto
backup
> server. What I want to do is find the failures, which are idenified by a
> line with "Unsuccessful save sets" then a blankish line, then the fialures
> then another blank line. What I'm thinking of doing if none has a better
> idea is searching for "unsuccessful save sets" finding the line number and
> the adding one and extracting a line at a time for analysis until a blank
> line, what I need to find out how to do is how to find the line number of
the
> line and how to extract lines given their number.
>
> Thanks,
> Mike.
>
> _______________________________________________
> Sderby mailing list
> Sderby@mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/sderby
> Web site: http://sderby.lug.org.uk/
> wiki: http://www.sderby.lug.org.uk/cgi-bin/wiki.pl
>