Views |
||||||||||||||
Locate Orphaned VSP Files
cathersal@gmx.net
'
' orphanedVSP.vbs
'
' Lists NB clients checks the root drives on them for leftOver VSP Files that are at least 2 days old
' 1.1 added blat so it can notify me everyday if it finds any.
'
' Needs to be run on Master
' S. Cathersal
' 2006-02-13
'
Option Explicit
' On Error Resume Next
Dim ObjFilesys, strLine, strFilename, Outputfile, Outputline
Dim objShell, Outputfilename, vmqueryOutput, quote
Dim ResultLine, strOutput, arySplit, strClient, objExec
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
quote = chr(34)
' Instantiate objects
Set ObjFileSys= CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
' Create Output Files
Outputfilename = objFileSys.GetParentFolderName(WScript.ScriptFullName) & "\OldVSPFiles.txt"
Set OutputFile = objFileSys.OpenTextFile(OutputFileName, OpenFileForWriting, true)
'----------------------------------------------------------------
' Main Section
'Create Header
OutputFile.writeline("Client Name" & VBTAB & "Drive Letter" & VBTab & "File Name" & VBTab & "File Size" & VBTab & "File Age in Days")
Call ListClients
Call Blat
outputfile.close
Wscript.quit
' -------------------------------------------------------------------------------------
Sub ListClients
Set vmqueryOutput = objshell.Exec ("F:\VERITAS\NetBackup\bin\admincmd\bpplclients.exe -allunique -l")
Do While Not VmqueryOutput.stdOut.atEndOfStream
ResultLine= VmqueryOutput.stdOut.readLine
If Instr(ResultLine,"PC") Then
arySplit = split(resultline," ")
strClient = trim(arySplit(1))
wscript.echo strClient
'If NB client is online, look for VSP files
If fctIsAlive(strClient) then
Call GetLogicalDrives(strClient)
End If
End If
Loop
End Sub
' -------------------------------------------------------------------------------------
Sub GetLogicalDrives(strClient)
Dim strFileShare, objFolder, objFiles, objFile, strExtension
Dim dtMod, dtDiff, objWMIService, colItems, objItem
'Turn off Error checking in case it is DMZ client
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strClient & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
If Err.number = 0 then
For Each objItem In colItems
If Instr (objItem.description,"Fixed Disk") then ' Only want local fixed disks
WScript.Echo "Netbackup Client = " & strClient & " Drives Caption: " & objItem.Caption
'Remove ":"
strFileShare= Replace(objItem.Caption,":", "$") ' replace the c: with c$ so I can connect to share
' Check root of drive for old VSP files
Set objFolder = objFileSys.GetFolder("\\" & strClient & "\" & strFileShare)
if err.number = 0 then
Set objFiles = objFolder.Files
For Each objFile in objFiles
strExtension = Right(objfile.name,4)
If strExtension = ".VSP" then
'Check file age
dtMod = objFile.DateLastModified
dtDiff = DateDiff("d", dtMod, now)
'See if VSP file is over 2 days old
If dtDiff > 1 then 'we found an old VSP file
OutputFile.writeline(strClient & VBTAB & objItem.Caption & VBTab & objFile.name & VBTab & objFile.size & VBTab & dtDiff)
End If
End If
Next
Else
wscript.echo "ERROR - Can't connect to \\" & strClient & "\" & strFileShare
err.clear
End If
End If
Next
Else
err.clear
End If
On Error Goto 0 'Stop on Errors Again
End Sub
' -------------------------------------------------------------------------------------
Sub Blat
Set objExec = objShell.Exec("blat.exe " & quote & Outputfilename & quote & " -to a@a.com -f master@a.com -server mailserver.a.com -s " & quote & "List of Servers with old VSP files" & quote)
End Sub
'********************************************************************************
'* Name: fctIsAlive.
'* Function: Check if the system is alive by pinging it.
'* Returns: True or False.
'* Returned Value: fctIsAlive.
'********************************************************************************
Function fctIsAlive(sysname)
Dim objPing, objStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& sysname & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then
fctIsAlive = False
Else
fctIsAlive = True
End If
Next
fctIsAlive = CBool(fctIsAlive)
Set objPing = nothing
End Function
|
||||||||||||||
| This page was last modified 14:38, 25 May 2007. | ||||||||||||||