All, Here is my script along with the readme. It's a long one....
/////////////////////////////////////
BEGIN README.....
////////////////////////////////////
NetBackup File Exclude Script, for Windows
Created by: Kevin Miele
Overview:
The NetBackup_UpdateExcludeList.vbs file provides a way for Windows
system administrators to quickly and easily update the NetBackup file
exclusion list on one or more servers. The script uses WMI to connect
to the registry of the specified machines and modifies the following
registry value:
Key Name:
HKEY_LOCAL_MACHINE\SOFTWARE\VERITAS\Netbackup\CurrentVersion\Config
Value Name: Exclude
• Note: You must have administrative rights on the server to update
the registry.
The script updates the Exclude value with the files specified in the
file exclude list input file. The script does not overwrite the
registry, it appends to the existing list. If the file already exists
in the registry then it will not write that file to it again.
Input Files:
The script requires 2 input files, a Server list and a File Exclude list
The Server list can contain a list of servers or if you want to run
this on the local machine, you can simply place a period, ".", in the
file.
Example: The Standard file exclusion list is as follows:
Create a text file with entries such as these: <excludelist.txt>
Perflib_Perfdata_*.dat
C:\Program Files\Altiris\Altiris
Agent\Tasks\AeXTaskSchedulerLock\taskSchedulerLock.tmp
C:\Program Files\Altiris\Altiris Agent\Software Delivery\pkgdlvlk.tmp
VSPCache*.vsp
Pagefile.sys
\bmc_data\*
*.tmp
Example: The SQL Standard file exclusion list contains these
additional exclusions:
*.ldf
*.mdf
SERVER LIST: <serverlist.txt>
create a text file with list of servers you want to perform the change on.
example:
server1
server2
server3
10.10.10.10
Output Files:
The script also creates two output files, an output log and an error log.
Script Usage:
c:\windows\system32\cscript.exe
c:\temp\Netbackup_UpdateExcludeList.vbs /readonly:<Yes or No>
/slist:<Server list File> /xlist:<Exclude list File> /outlog:<Output
Logfile> /errlog:<Error Logfile>"
Example: c:\windows\system32\cscript.exe
c:\temp\Netbackup_UpdateExcludeList.vbs /readonly:Yes
/slist:c:\temp\serverlist.txt /xlist:c:\temp\FileExcludeList.txt
/outlog:c:\temp\Output.log /errlog:c:\temp\Error.Log
Arguments: All arguments, except for /?, are required.
/? Shows the usage screen
/readonly: Sets the script to perform processes in readonly mode
Yes – Write changes to registry
No – Only read the registry
/slist: Server List file
- Can contain a list of servers or a period, "." for the local server
- Define both path and file name
/xlist: File Exclude List file
- Contains a list of files or paths to exclude in Netbackup for
the clients listed in the server list file.
- Define both path and file name
/outlog: Output Log file
- Contains all output of the script.
- Define both path and file name
/errlog: Error Log file
- Contains only errors produced by the script
- Define both path and file name
NOTE: A .cmd file can be created to alleviate the need for typing the
arguments repeatedly.
Script Standard and Log Output:
• Note: In this example Readonly is set to 'Yes'. This simply reads
the registry and nothing more.
In order to actually make changes to the registry the Readonly
argument must be set to 'No'.
• The log file is comma delimited so that you can import it into
Excel easily.
**********************************************************************************
* Name: NetBackup Client File Exclude
List Updater, for Windows
* Date: 4/13/2006
* Time: 2:00:20 PM
* Server List: c:\temp\SQL_serverlist.txt
* Exclude List: c:\temp\FileExcludeList_SQLServers.txt
* Readonly (Yes/No): Yes
* Created By: Kevin Miele, Enterprise Backup
**********************************************************************************
4/13/2006 2:00:20 PM,NoComputerName,Function: START
SCRIPT,**********************************************************************************
4/13/2006 2:00:20 PM,ad2hfdsqln02,Function: ReadExcludeFileList,File
to Exclude: Perflib_Perfdata_*.dat
4/13/2006 2:00:25 PM,ad2hfdsqln02,Function:
ReadMultiStringRegistry,Error: -2147217405,Unknown Error
encountered,Line: Set oRegistry = GetObject
4/13/2006 2:00:26 PM,ad2hfdsqltn1,Function: ReadExcludeFileList,File
to Exclude: Perflib_Perfdata_*.dat
4/13/2006 2:00:31 PM,ad2hfdsqltn1,Function:
ReadMultiStringRegistry,Error: -2147217405,Unknown Error
encountered,Line: Set oRegistry = GetObject
4/13/2006 2:00:31 PM,ad2mtlsql001,Function: ReadExcludeFileList,File
to Exclude: Perflib_Perfdata_*.dat
4/13/2006 2:00:37 PM,ad2mtlsql001,Function:
ReadMultiStringRegistry,Error: -2147217405,Unknown Error
encountered,Line: Set oRegistry = GetObject
////////////////////////////////////
END README........
//////////////////////////////////
Make it a .vbs file
I suggest creating a cmd file to run it as stated in the read me above.
///////////////////////////////
BEGIN SCRIPT
///////////////////////////////
' Filename: Netbackup_UpdateExcludeList.vbs
' Author: Kevin Miele
' Date: 5/15/2008
' Purpose: To append to the current File Exclude list on a Windows
Netbackup Client.
' This script modifies the registry under:
' KeyName:
HKEY_LOCAL_MACHINE\SOFTWARE\VERITAS\Netbackup\CurrentVersion\Config
' ValueName: Exclude (Multistring)
'
' Output: This script outputs the ComputerName, the value of the
registry before it is changed
' and the value of the registry after it is changed, as
well as, some other information.
'
' Modify ONLY: The two global path variables
'
' Notes: This script uses the Registry object 'StdRegProv' through WMI.
' Notes: YOU WILL NEED ADMINISTRATIVE RIGHTS TO EXECUTE THIS
SCRIPT, it modifies the registry.
' Updated: 3/2/2006, Kevin Miele, Added Error Handling, Logging,
EchoMessage Routine.
'-------------------------------------------------------------------------------
Option Explicit
'Global Variables
Dim index
Dim g_strFilename
DIM g_strExcludeFilename
Dim g_arrFileListAppended()
Dim g_intNewIndexNumber
Dim g_intOriginalArraySize ' Contains the array size of the registry value
Dim g_strNewFileToexclude
Dim g_blnExcludeExists
Dim g_blnErrorsOccurred ' Were there any errors in the script?
Dim g_blnReadOnly ' This is a variable that will be used
to turn the
' read only feature on and off.
'Yes = READONLY
'No = Write/Change
Dim g_OutPutLogFile
Dim g_ErrorLog
'Variable to tell if there were errors for the exit message.
g_blnErrorsOccurred = False
'Start the Script.
Call ProcessWork()
Sub ProcessWork()
' Author: Kevin Miele
' Date: 1/17/2006
' Purpose: Process all the major routines
Const strFunctionName = "ProcessWork"
Dim strComputerName
Dim objfso
Dim objOpenTextFile
Dim strMsg
'Check the arguments
IF Arguments = True Then
'run the script
Else
Call Usage()
End If
strMsg = "Set objFSO = CreateObject"
Set objfso = CreateObject("Scripting.FilesystemObject")
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "Set objOpenTextFile"
'open the Server list text file to read
Set objOpenTextFile = objfso.OpenTextFile(g_strFilename)
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
'Display Header
WScript.Echo
"**********************************************************************************"
WScript.Echo "* Name: " & "NetBackup Client
File Exclude List Updater, for Windows"
WScript.Echo "* Date: " & Date
WScript.Echo "* Time: " & Time
WScript.Echo "* Server List: " & g_strFilename
WScript.Echo "* Exclude List: " & g_strExcludeFilename
WScript.Echo "* Readonly (Yes/No): " & g_blnReadOnly
WScript.Echo "* Created By: " & "Kevin Miele,
Enterprise Backup"
WScript.Echo
"**********************************************************************************"
WScript.Echo ""
strMsg =
"**********************************************************************************"
Call EchoMessage(strMsg,"START SCRIPT","NoComputerName",True)
'Loop through the text file and read each line
Do Until objOpenTextFile.AtEndOfStream
'Read each line of the Text File
'WScript.Echo objOpenTextFile.ReadLine
'Set file existence to false initially for each computer
g_blnExcludeExists = False
'Set the computername
strComputerName = objOpenTextFile.ReadLine
'Tell the User the computer name that is being Read
'WScript.Echo
"=============================================================="
'WScript.Echo "ComputerName: " & strComputerName
'Read the file exclude list and append it to the exclude
list in the registry
Call ReadExcludeFileList(strComputerName, g_strExcludeFilename)
Loop
strMsg = "objOpenTextFile.Close"
'Close the file when done.
objOpenTextFile.Close
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
'Clean up objects
Set objfso = Nothing
Set objOpenTextFile = Nothing
Call ExitScript(0,strComputerName)
End Sub
Function ReadExcludeFileList(strComputerName, g_strExcludeFilename)
'Author: Kevin Miele
'Date: 02/16/2006
'Purpose: To read the file exclusion list and append to the
current exclusion list.
On Error Resume Next
Const strFunctionName = "ReadExcludeFileList"
Dim objfso
Dim objOpenTextFile
Dim strFileToExclude
Dim strMsg
strMsg = "Set objfso = CreateObject"
Set objfso = CreateObject("Scripting.FilesystemObject")
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "Set objOpenTextFile"
Set objOpenTextFile = objfso.OpenTextFile(g_strExcludeFilename)
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "Do Until"
Do Until objOpenTextFile.AtEndOfStream
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "strFileToExclude = ObjOpenTextFile.ReadLine"
'Read each line of the Text File
strFileToExclude = objOpenTextFile.ReadLine
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "File to Exclude: " & strFileToExclude
Call EchoMessage(strMsg,strFunctionName,strComputerName,False)
'WScript.Echo "Before..."
If ReadMultiStringRegistry(strComputerName,strFileToExclude)
= True Then
'Write the File only if it doesn't exist.
If g_blnExcludeExists = False Then
'Decide if Script will only read the registry or
read and write to the registry.
Select Case g_blnReadOnly
Case "Yes"
strMsg = "Exclude file doesn't exist ...
would have made registry change."
Call
EchoMessage(strMsg,strFunctionName,strComputerName,False)
'Write is enabled
Case "No"
If
SetMultiStringRegistry(strComputerName,strFileToExclude)= True Then
strMsg = "Verifying Exclusion List:"
Call
EchoMessage(strMsg,strFunctionName,strComputerName,False)
'Read the registry value List
Call
ReadMultiStringRegistry(strComputerName,strFileToExclude)
End If
Case Else
strMsg = "g_blnReadonly not set to Yes or No"
'Cause a critical error
Call
ErrorCheck(strComputerName,strMsg,"1",strFunctionName,True)
End Select
Else
strMsg = "File Exists, no need to append."
Call
EchoMessage(strMsg,strFunctionName,strComputerName,False)
End If
Else
'exit function because we cannot contact the client
Exit Function
End If
'Display a blank line.
'strMsg = ""
'Call EchoMessage(strMsg,strFunctionName,strComputerName,False)
'reset back to false to put variable in its beginning state.
g_blnExcludeExists = False
Loop
strMsg = "objOpenTextFile.close"
'Close the file when done.
objOpenTextFile.Close
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,False)
Set objfso = Nothing
End Function
Function ReadMultiStringRegistry(sComputer,strFileToExclude)
' Author: Kevin Miele (Along with some internet resources)
' Date: 1/17/2006
' Purpose: To Read a multi-string registry value on local and
remote computers
' Parameters: sComputer - this is a string of the computername
On Error Resume Next
Const strFunctionName = "ReadMultiStringRegistry"
'Setup Constants needed by the routine to access the registry in Hex
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
'Setup Variables to be used throughout the routine.
Dim strMultiStringValue 'Holds the appended version of all
values in the array
Dim strQuote ' A quote "
Dim sMethod ' The method being performed in the registry
Dim hTree ' Hive Tree (example HKEY_LOCAL_MACHINE)
Dim sKey ' The actual key within the tree:
(example SOFTWARE\VERITAS\Netbackup\CurrentVersion\Config)
Dim sValue ' string value of the value
Dim oMethod ' object method
Dim oInparam ' object input parameter
Dim oOutParam ' object output parameter
Dim i ' Array counter
Dim c ' Another array Counter
Dim oRegistry ' Registry object
Dim strArrayValue
Dim strMsg
strQuote = """"
'Dim g_arrFileListAppended()
'sComputer = g_ComputerName
sMethod = "GetMultiStringValue"
hTree = HKEY_LOCAL_MACHINE
sKey = "SOFTWARE\VERITAS\Netbackup\CurrentVersion\Config"
sValue = "Exclude"
strMsg = "Set oRegistry = GetObject"
'Connect to the registry of the given computername
Set oRegistry =
GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/default:StdRegProv")
'Check for errors in connecting to the registry
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
g_blnErrorsOccurred = True
Exit Function
End If
strMsg = "Set oMethod = oRegistry"
'Setup registry objects
Set oMethod = oRegistry.Methods_(sMethod)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
Exit Function
End If
strMsg = "Set oInparam = oMethod.inParameters"
Set oInparam = oMethod.inParameters.SpawnInstance_()
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
Exit Function
End If
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValue
strMsg = "Set oOutParam"
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
Exit Function
End If
'WScript.Echo oOutParam.Properties_("sValue")
strMsg = "ArrayEmpty"
g_intOriginalArraySize = UBound(oOutParam.Properties_("sValue"))
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
'wscript.echo "Err Number: " & err.number & ", " &
"Description: " & err.description
strMsg = "Current Number of File Exclusions: 0"
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
g_intOriginalArraySize = 0
Else
If UBound(oOutParam.Properties_("sValue")) = -1 Then
strMsg = "Array Size is -1, it contains no entries."
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
strMsg = "Current Number of File Exclusions: 0"
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
g_intOriginalArraySize = -1
Else
strMsg = "No Error"
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
strMsg = "Current Number of File Exclusions: " &
g_intOriginalArraySize + 1
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
End If
End If
strMsg = "Current Array Size: " & g_intOriginalArraySize
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
strMsg = "ReDIM g_arrFileListAppended"
'Resize the new array to the same size as the array we are reading.
'Resizing the array allows us to populate the array appropriately.
ReDim g_arrFileListAppended(g_intOriginalArraySize)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
Exit Function
End If
For i=0 To UBound(oOutParam.Properties_("sValue"))
'WScript.Echo oOutParam.Properties_("sValue")(i)
'This is an IF statement because if the array has only 1 item
we don't want to add multiple items of the same
'thing to the new array. Notice the 'strMultiStringValue = ' lines.
If I = 0 Then
strMultiStringValue = strQuote &
oOutParam.Properties_("sValue")(i) & strQuote
'populate the new array with the original file list info.
strArrayValue = oOutParam.Properties_("sValue")(i)
'Check if the file to exclude already exists, if so, then
stop reading the array and go to the next computer.
If CheckIfFileExcludeExists(strArrayValue,strFileToExclude)
= True Then
strMsg = "File to Exclude exists in the list." & "
File to exclude: " & strArrayValue
Call EchoMessage(strMsg,strFunctionName, sComputer,False)
End If
'Add to new array.
g_arrFileListAppended(i) = strArrayValue
Else
strMultiStringValue = strMultiStringValue & "," & strQuote
& oOutParam.Properties_("sValue")(i) & strQuote
strArrayValue = oOutParam.Properties_("sValue")(i)
'Check if the file to exclude already exists, if so, then
stop reading the array and go to the next computer.
If CheckIfFileExcludeExists(strArrayValue,strFileToExclude)
= True Then
strMsg = "File to Exclude exists in the list." & "
File to exclude: " & strArrayValue
Call EchoMessage(strMsg,strFunctionName, sComputer,False)
End If
strMsg = "g_arrFileListAppended(i) ="
'Add to the new array
g_arrFileListAppended(i) = strArrayValue
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
ReadMultiStringRegistry = False
Exit Function
End If
End If
Next
'Display the new string that will be written
strMsg = "Netbackup File Exclude List: " & strMultiStringValue
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
'Clean Up Objects
Set oRegistry = Nothing
Set oMethod = Nothing
Set oInParam = Nothing
Set oOutParam = Nothing
ReadMultiStringRegistry = True
End Function
Function CheckIfFileExcludeExists(strFileToCheck,strFileToExclude)
'Author: Kevin Miele
'Date: 2/14/2005
'Purpose: To check if the excluded file exists
'Returns: True or False
Const strFunctionName = "CheckIfFileExcludeExists"
If strFileToCheck = strFileToExclude Then
CheckIfFileExcludeExists = True
g_blnExcludeExists = True
Else
CheckIfFileExcludeExists = False
End If
End Function
Function SetMultiStringRegistry(sComputer, strFileToExclude)
' Author: Kevin Miele and internet resources
' Date: 1/17/2006
' Purpose: To append to an existing registry value, this
appends 1 item at a time
' to the specified multistring registry key.
' Parameters: sComputer - is the computername string.
On Error Resume Next
Const strFunctionName = "SetMultiStringRegistry"
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Dim sMethod
Dim hTree
Dim sKey
Dim aValue
Dim sValueName
Dim oMethod
Dim oInparam
Dim oOutParam
Dim i
Dim oRegistry
Dim strNewFileToexclude
Dim intArrayUboundValue
Dim intNumberOfElementsToAdd
Dim strMsg
'How many items to add to the registry list
intNumberOfElementsToAdd = 1
'Resize and preserve what was written to the array
strMsg = "ReDIM Preserve"
ReDim Preserve g_arrFileListAppended(g_intOriginalArraySize +
intNumberOfElementsToAdd)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
Exit Function
Else
strMsg = "New Number of File Exclusions: " &
UBound(g_arrFileListAppended) + 1
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
End If
strMsg = "intArrayUboundValue"
'Get the size of the array
intArrayUboundValue = Ubound(g_arrFileListAppended)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
Exit Function
End If
'Append the 1 extra item to the array list
g_arrFileListAppended(intArrayUboundValue) = strFileToExclude
'Debugging code commented out.
' 'What's in the new array?
' WScript.Echo "Show me what's in the new array."
' For i = 0 To UBound(g_arrFileListAppended)
' WScript.Echo g_arrFileListAppended(i)
' Next
'sComputer = "MyComputer"
sMethod = "SetMultiStringValue"
hTree = HKEY_LOCAL_MACHINE
sKey = "SOFTWARE\VERITAS\Netbackup\CurrentVersion\Config"
sValueName = "Exclude"
'aValue = g_arrFileListAppended()
strMsg = "Set oRegistry = Getobject"
'Connect to the registry
Set oRegistry =
GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/default:StdRegProv")
'check for errors connecting to the registry
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
Exit Function
Else
'keep going in the script.
strMsg = "Appending New File to exclusion list."
Call EchoMessage(strMsg,strFunctionName,sComputer,False)
End If
'Setup registry objects
strMsg = "Set oMethod = oRegistry"
Set oMethod = oRegistry.Methods_(sMethod)
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
Exit Function
End If
strMsg = "Set oInParam = oMethod"
Set oInParam = oMethod.inParameters.SpawnInstance_()
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
Exit Function
End If
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValueName
oInParam.sValue = g_arrFileListAppended 'aValue
strMsg = "Set oOutParam = oRegistry"
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
'Check for errors in writing to the registry.
If
ErrorCheck(sComputer,Err.Description,Err.Number,strFunctionName,strMsg,False)
= True Then
'The function was not successful
SetMultiStringRegistry = False
Exit Function
Else
'The function was successful
SetMultiStringRegistry = True
End If
'Clean Up Objects.
Set oRegistry = Nothing
Set oMethod = Nothing
Set oInParam = Nothing
Set oOutParam = Nothing
End Function
Function
ErrorCheck(strComputerName,strDescription,intErrNumber,strFunctionName,strLine,blnCritical)
' Author: Kevin Miele
' Date: 03/2/2006
'Purpose: To handle All errors that occur.
Const sFunctionName = "ErrorCheck"
Const NoError = 0
Const TypeMisMatchErr = 13
Const strComma = ","
Const strQuote = """"
Dim strErrDesc
Dim intErrNum
Dim strMsg
'Populate the variables with the information from the arguments
strErrDesc = strDescription
intErrNum = intErrNumber
'Clear the error
Err.Clear
Select Case intErrNum
Case NoError
'No Error exit the function
ErrorCheck = False
Exit Function
Case TypeMisMatchErr
If strLine = "ArrayEmpty" Then
'Not an Error
ErrorCheck = False
Exit Function
End If
Case Else
If strErrDesc = "" Then
strErrDesc = "Unknown Error encountered"
End If
End Select
'Decide what to do
' Is it a Critical Error, True/Yes, False/No
Select Case blnCritical
Case True
strMsg = "Error: " & intErrNum & strComma & strErrDesc &
strComma & "Line: " & strLine
Call EchoMessage(strMsg,strFunctionName,strComputerName,True)
Call ExitScript(1,strComputerName)
Case False
strMsg = "Error: " & intErrNum & strComma & strErrDesc &
strComma & "Line: " & strLine
Call EchoMessage(strMsg,strFunctionName,strComputerName,True)
'There was an error
g_blnErrorsOccurred = True
ErrorCheck = True
Case Else
strMsg = "Critical or Not Critical Unknown, exiting"
Call EchoMessage(strMsg,strFunctionName,True)
Call ExitScript(1,strComputerName)
End Select
strErrDesc = ""
intErrNum = ""
strLine = ""
End Function
Function EchoMessage(strMessage,strFunctName,strComputerName,blnError)
' Author: Kevin Miele
' Date: 03/2/2006
' Purpose: To echo messages in a specific format every time,
handles both normal and error messages
Const sFunctionName = "EchoMessage"
Const strComma = ","
Dim strDateTime
Dim strMsg
strDateTime = Date & " " & Time
strMsg = strDateTime & strComma & strComputerName & strComma &
"Function: " & strFunctName & strComma & strMessage
WScript.Echo strMsg
'If the message is not an error message then only write to the output log
'If the message is an error message then write to both logs.
If blnError = False then
Call WriteLog(g_OutPutLogFile,strMsg,strComputerName)
Else
Call WriteLog(g_OutPutLogFile,strMsg,strComputerName)
Call WriteLog(g_ErrorLog,strMsg,strComputerName)
End If
EchoMessage = strMsg
End Function
Sub WriteLog(strLogFileName,strData,strComputerName)
'Author : Kevin Miele
'Date : 7/13/2004, updated 03/2/2005
'Purpose : Write The log file
On Error Resume Next
Const strFunctionName = "WriteLog"
Const ForAppending = 8
Const ForWriting = 2
Dim objFSO
Dim objWriteFile
Dim objCreateFile
Dim strMsg
strMsg = "Set objFSO"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "objFSO.FileExists"
If objFSO.FileExists(strLogFileName) Then
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
'objFSO.DeleteFile(strLogFileName)
Else
strMsg = "Set objCreateFile"
Set objCreateFile = objFSO.CreateTextFile(strLogFileName)
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "objCreateFile.Close"
objCreateFile.Close
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
End If
strMsg = "Set objWriteFile ="
Set objWriteFile = objFSO.OpenTextFile(strLogFileName,ForAppending)
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "ObjWriteFile.WriteLine"
objWriteFile.WriteLine strData
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
strMsg = "objWriteFile.Close"
objWriteFile.Close
Call
ErrorCheck(strComputerName,Err.Description,Err.Number,strFunctionName,strMsg,True)
'Clear Objects
set objFSO = Nothing
Set objWriteFile = Nothing
set objCreateFile = Nothing
End Sub
Sub ExitScript(intExitCode,strComputerName)
' Author: Kevin Miele
' Date: 3/2/2006
' Purpose: To exit the script in one location
Const strFunctionName = "ExitScript"
Dim strMsg
Dim strExitMsg
If intExitCode = 1 or g_blnErrorsOccurred = True Then
strExitMsg = "Script Completed with Errors"
'Message to output at the end of the script
strMsg = strExitMsg
Call EchoMessage(strMsg,strFunctionName,strComputerName,False)
WScript.Quit(intExitCode)
Else
strExitMsg = "Script Completed Successfully"
'Message to output at the end of the script
strMsg = strExitMsg
Call EchoMessage(strMsg,strFunctionName,strComputerName,False)
WScript.Quit(intExitCode)
End If
End Sub
Function Arguments()
' Author: Kevin Miele
' Date: 4/15/03
' Purpose: Allows the Script to accept Argument
Dim objArgsNamed ' Named Arguments Variable
Set objArgsNamed = WScript.Arguments.Named ' Set Named Arguments Object
g_strFilename = WScript.Arguments.Named.Item("slist") ' SourcePath argument
g_strExcludeFilename = WScript.Arguments.Named.Item("xlist")' Log
File Path argument
g_OutPutLogFile = WScript.Arguments.Named.Item("outlog")' Log File
Name argument
g_ErrorLog = WScript.Arguments.Named.Item("errlog")' Errlog File
Name argument
g_blnReadOnly = WScript.Arguments.Named.Item("readonly")
'Check Usage - If anyone of the arguments is missing show usage.
If objArgsNamed.Exists("slist")= False Or
objArgsNamed.Exists("xlist")= False or objArgsNamed.Exists("outlog")=
False _
or objArgsNamed.Exists("errlog")= False
or objArgsNamed.Exists("?")= True Then
' Show the user how to use the script
Call Usage
Else
Arguments = True
End If
End Function
Sub Usage()
' Author: Kevin Miele
' Date: 4/15/03
' Purpose: Show the user how to use the script
On Error Resume Next
WScript.Echo "Usage:"
WScript.Echo "cscript.exe Netbackup_UpdateExcludeList.vbs /? -
shows this screen"
WScript.Echo "cscript.exe Netbackup_UpdateExcludeList.vbs
/readonly:<Yes or No> /slist:<Server list File> /xlist:<Exclude list
File> /outlog:<Output Logfile> /errlog:<Error Logfile>"
WScript.Echo "Example: cscript.exe
c:\temp\Netbackup_UpdateExcludeList.vbs /readonly:Yes
/slist:c:\temp\serverlist.txt /xlist:c:\temp\FileExcludeList.txt
/outlog:c:\temp\Output.log /errlog:c:\temp\Error.Log"
WScript.Quit
End Sub
//////////////
End Script
///////////////
NOTE: The last 2 Wscript.echo lines are word wrapped in the email, you
will have to make sure each Wscript.echo command are one line each
Let me know if you need assistance.
Regards,
Kevin Miele
_______________________________________________
Veritas-bu maillist - Veritas-bu AT mailman.eng.auburn DOT edu
http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu
|