[Sderby] PERL again!

Mini Mike sderby at mailman.lug.org.uk
Mon Jan 13 20:18:00 2003


Thanks, Andre.  I've had a play with your last script but couldn't get it=
 to=20
work.  I've been a bit busy last week so didn't get a change to do any=20
debuging.  Will have a play hopfully this week.

Thanks again,

Mike.

On Monday 13 January 2003 10:50, andre.hefer@avhservices.co.uk wrote:
> 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=
=2E
>
> Andre
>
> PS This code assumes that the legato file and the perl script are in th=
e
> same directory.
>
> #!/usr/bin/perl -w
> # script name:Legato.pl Extracts multiline error message
> use strict;
> use IO::Handle;
>
> my $mylegatofile=3D "Name of backuplog"; #Legato backup file
> my $myfailfile=3D "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 =3D "";
> my $messagestartflag =3D "false"; #Flag switched to true when start of
> message is detected
> my $messagecompleteflag =3D "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 detec=
ts
> start of message
>         $tempmessage=3D  $1; #Capture start of error message
>         $messagestartflag =3D "true";
>     }
>     if($messagestartflag =3D=3D "true" && $messagecompleteflag =3D=3D "=
false"){
> #Still within body of error message
>         $tempmessage .=3D $_; #Add new line read onto tempmessage
>     }
>     if(/^.*(?:Text which identifies end if message)$.*/so){ #Regular
> Expression detects end of  error message
>         $messagecompleteflag =3D "true"; #Capture start of error messag=
e
>     }
>     if($messagestartflag =3D=3D "true" && $messagecompleteflag =3D=3D "=
false"){
> #Still within body of error message
>         print LOGFILE "$tempmessage\n";
>         $messagestartflag =3D "false";$messagecompleteflag =3D "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 l=
ine
> > number and the adding one and extracting a line at a time for analysi=
s
> > 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
>
> _______________________________________________
> 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