Submitted By: David Gray

Perl script to extract Error and Warning messages from a Backup Exec log file.

Visual Basic
Edit|Remove
#*******************************************************************************
#	Filename:		BELogScan.pl
#
#	Synopsis:		Perl Script that filters error messages from a Backup Exec
#					log file into a new text file.
#
#	Syntax:			BELogScan.vbs InputLog OutputLog
#
#					where:	InputLog	= Name of Backup Exec log to filter.
#
#							OutputLog	= Name of file to hold error messages.
#
#					OutputLog will be created if it does not exist, and new
#					records will be appended to it if it does.
#
#	Details:		Records are filtered to include items with one of the following
#					prefixes:
#
#					##WRN##
#					##ERR##
#
#	Author:			David A. Gray, Chief Wizard
#					Simple Soft Services, Inc., d/b/a WizardWrx
#                   Wizard Wells, Texas, USA.
#
#	Date Written:	Saturday, 24 December 2005
#
#	NOTICE:			THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
#					WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
#					INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
#					OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#
#	Copyright:		(C) 2005 Simple Soft Services, Inc., d/b/a WizardWrx,
#   	            Wizard Wells, Texas, USA.
#                   All rights reserved world wide.
#
#*******************************************************************************

#	Get arguments.

use integer ;												# Save the FPU for when we really need it.
$nargs = @ARGV ;

# Test the command line.

if ( $nargs > 1 ) {
    print "BELogScan.vbs Begin\n" ;

	# Open input and output files. Complain, but continue, if too many arguments.

	$beinplogname = $ARGV [ 0 ] ;
	$beoutlogname = $ARGV [ 1 ] ;
    warn "Input file:  $beinplogname\nOutput file: $beoutlogname\n" ;
	if ( $nargs > 2 ) {
		warn "Too many arguments - extra arguments ignored\n" ;
	}
	unless ( open ( IN , "$beinplogname" ) ) {
		die "ABORTING: Unable to open input file $beinplogname\a\n" ;
	}
	unless ( open ( OUT , ">>$beoutlogname" ) ) {
		die "ABORTING: Unable to open output file $beoutlogname\a\n" ;
	}

	# Initialize all counters to zero.

	$nrecstot		= 0 ;
	$nrecslogged	= 0 ;
	$nwarnings		= 0 ;
	$nerrors		= 0 ;
	$nrecsskipped	= 0 ;

	# Filter the records into the output file.

	while  ( <IN> ) {
		++$nrecstot ;
		if ( /^##WRN##/ ) {
			++$nwarnings ;
			++$nrecslogged ;
			print OUT $_ ;
			warn "Record $nrecstot is a Warning\n" ;
		} else {
			if ( /^##ERR##/ ) {
				++$nerrors ;
				++$nrecslogged ;
				print OUT $_ ;
				warn "Record $nrecstot is an Error\n" ;
			} else {
				++$nrecsskipped ;
			}
		}
		if ( $nrecstot % 100 == 0 ) {
			warn "$nrecstot records read\n" ;
		}
	}

	# Close file handles and destroy objects.

	close IN ;
	close OUT ;

	#	Summarize activity.

	print STDERR <<MSG1;

Finished processing of $beinplogname

    Warnings logged     = $nwarnings
    Errors logged       = $nerrors
Total Records logged    = $nrecslogged
Records skipped         = $nrecsskipped
Total records processed = $nrecstot

Output written to $beoutlogname

MSG1
	exit ( 0 ) ;
} else {
	print STDERR <<MSG2;
BELogScan.vbs InputLog OutputLog

where:    InputLog	= Name of Backup Exec log to filter.

          OutputLog	= Name of file to hold error messages.

OutputLog will be created if it does not exist, and new records will be
appended to it if it does.

Please submit a valid command.
MSG2
   	exit ( 1 ) ;
}