Submitted By: David Gray

VBScript script to extract Error and Warning level messages from a Backup Exec log.

Visual Basic
Edit|Remove
'*******************************************************************************
'	Filename:		BELogScan.vbs
'
'	Synopsis:		VB 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.
'
'*******************************************************************************

option explicit

'	Define constants.

Const ForReading	= 1
Const ForWriting	= 2
Const ForAppending	= 8

'	Declare variables.

dim intNArgs
dim intNErrors
dim intNRecsTot
dim intNRecsLogged
dim intNRecsSkipped
dim intNWarnings
dim objArgs
dim objFSO
dim objInFile
dim objOutFile
dim strBEInpLogName
dim strBEOutLogName
dim strInRec

'	Get arguments.

set objArgs = WScript.Arguments
intNArgs = objArgs.Count

' Test the command line.

if intNArgs > 1 then
    WScript.Echo "BELogScan.vbs Begin"

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

	strBEInpLogName = objArgs(0)
	strBEOutLogName = objArgs(1)
    WScript.Echo "Input file:  " & strBEInpLogName
    WScript.Echo "Output file: " & strBEOutLogName
	if intNArgs > 2 then
		WScript.Echo "Too many arguments - extra arguments ignored"
	end if
	Set objFSO	= CreateObject("Scripting.FileSystemObject")
	set objInFile	= objFSO.OpenTextFile ( strBEInpLogName , ForReading )
	set objOutFile	= objFSO.OpenTextFile ( strBEOutLogName , ForAppending , True )

	' Initialize all counters to zero.

	intNRecsTot 	= 0
	intNRecsLogged	= 0
	intNWarnings	= 0
	intNErrors		= 0
	intNRecsSkipped	= 0

	' Filter the records into the output file.

	do
		strInRec	= objInFile.ReadLine
		intNRecsTot	= intNRecsTot + 1
		if left ( strInRec , 7 ) =  "##WRN##" then
			intNWarnings	= intNWarnings + 1
			intNRecsLogged	= intNRecsLogged + 1
			objOutFile.WriteLine ( strInRec )
			WScript.Echo "Record " & intNRecsTot & " is a Warning"
		else
			if left ( strInRec , 7 ) =  "##ERR##" then
				intNErrors		= intNErrors + 1
				intNRecsLogged	= intNRecsLogged + 1
				objOutFile.WriteLine ( strInRec )
				WScript.Echo "Record " & intNRecsTot & " is an Error"
			else
				intNRecsSkipped	= intNRecsSkipped + 1
			end if
		end if

		if intNRecsTot mod 100 = 0 then
			WScript.Echo intNRecsTot & " records read"
		end if
	loop until objInFile.AtEndOfStream

	' Close file handles and destroy objects.

	objOutFile.Close ( )
	objInFile.Close ( )

	set objOutFile	= nothing
	set objInFile	= nothing
	set objFSO		= nothing

	'	Summarize activity.

	WScript.Echo ""
	WScript.Echo "Finished processing of " & strBEInpLogName
	WScript.Echo ""
	WScript.Echo "    Warnings logged     = " & intNWarnings
	WScript.Echo "    Errors logged       = " & intNErrors
	WScript.Echo "Total Records logged    = " & intNRecsLogged
	WScript.Echo "Records skipped         = " & intNRecsSkipped
	WScript.Echo "Total records processed = " & intNRecsTot
	WScript.Echo ""
	WScript.Echo "Output written to " & strBEOutLogName
    WScript.Quit (0)
else
    WScript.Echo "BELogScan.vbs InputLog OutputLog"
    WScript.Echo ""
    WScript.Echo "where:    InputLog	= Name of Backup Exec log to filter."
    WScript.Echo ""
    WScript.Echo "          OutputLog	= Name of file to hold error messages."
    WScript.Echo ""
    WScript.Echo "OutputLog will be created if it does not exist, and new records will be"
    WScript.Echo "appended to it if it does."
    WScript.Echo ""
    WScript.Echo "Please submit a valid command."	
	WScript.Quit (1)
end if