|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
Read RoboCopy Log Files(Community)
Script Code
VBScript
' Name: CheckRobo.sys
' Title: Extract job summary from Robocopy log files ' Synopsis: This script extracts errors and totals from a Robocopy
' version 4.0.1.96 log file and writes them to a file to provide ' a summary of a Robocopy job.
'
' Sample output
'
************************************************************************
**
'C:\Batch\CopySYS.cmd Robocopy completed with errors ' Started : Tue Jan 17 23:00:01 2006
' Source = D:\SYS\
' Dest = X:\SYS\Tuesday\
' Files : *.*
' ERROR 32 (0x00000020) Copying File D:\SYS\APPS\NewApp\42140831.CDX ' ERROR 32 (0x00000020) Copying File D:\SYS\APPS\NewApp\42140831.dbf
' Total Copied Skipped Mismatch FAILED Extras
' Dirs : 8568 118 8450 0 0 101
' Files : 92252 649 91588 0 15 355
' Bytes :150117.417 g 130.72 m149385.290 g 0 11.1 k
52.96 m
' Times : 0:14:52 0:08:04 0:00:00 0:06:47
' Ended : Tue Jan 17 23:14:53 2006
'
************************************************************************
*****
Dim fso, oTextIn, oTextout
Dim sInFile, sOutFile, sData, sTabline, sToken Dim bForceNewOutput, bAppending, bOK, iPtr
Dim aKeywords
Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
aKeywords = array("started","source","dest","error","access","total","dirs","files","bytes","times","ended")
'
Set oArgs = WScript.Arguments
bOk = True
sTabline = VBTAB + string(30," ")
if oArgs.count < 2 then
WScript.Echo "Syntax: cscript <path>\CheckRobo.vbs <Robocopy
logfile> <ResultsFile> [[/]n]"
WScript.Echo "/n = create new file (delete existing), otherwise append to existing file" + VBCRLF
Err.Raise 1
end if
'
sInFile = oArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
'
if fso.FileExists(sInFile) then
Set oTextIn = fso.OpenTextFile(sInFile) else
Wscript.Echo "Input file" + sInFile + "not found"
Err.Raise 2
end if
'
bForceNewOutput = False
'
if oArgs.Count = 3 then
if (lcase(oArgs(2)) = "/n" or lcase(oArgs(2)) = "n") then
bForceNewOutput = True
end if
end if
'
' Setup output file
sOutFile = oArgs(1)
wscript.echo "Output = " + sOutFile
If fso.FileExists(sOutFile) then
wscript.echo "Output exists"
if bForceNewOutput then
wscript.echo "Forcing New Output"
set oTextOut = fso.GetFile(sOutFile)
oTextOut.Delete
Set oTextout = fso.OpenTextFile(sOutFile, ForWriting,
True)
bAppending = False
else
wscript.echo "Appending to Output " + sOutFile
Set oTextout = fso.OpenTextFile(sOutFile, ForAppending,
True)
bAppending = True
end if
else
wscript.echo "Output not found, creating"
Set oTextout = fso.OpenTextFile(sOutFile, ForWriting, True)
bAppending = False
end if
'
' Process log file
Do Until oTextIn.AtEndOfStream
sData = oTextIn.Readline
sToken = trim(FirstWord(lcase(sData)))
if len(sToken) > 0 and IsAKeyword(sToken) then
oTextout.WriteLine(sData)
end if
Loop
oTextout.Close
oTextIn.Close
'
'**************************FUNCTIONS*******************************
' isolate first or only character string function FirstWord(sTextLine)
dim iStart, iEnd, iMid
iStart = 1
iEnd = len(sTextLine)
if iEnd < 3 then ' skip empty and tab-only lines
FirstWord = ""
exit function
end if
Do While ((mid(sTextLine,iStart,1) = vbTab or
mid(sTextLine,iStart,1) = " " _
or mid(sTextLine,iStart,1) = "-") and iStart <
iEnd)
iStart = iStart + 1
Loop
'
if iStart >= iEnd then
FirstWord = ""
exit function
end if
iMid = iStart + 1
Do While iMid < iEnd and mid(sTextLine,iMid,1) <> " "
iMid = iMid + 1
Loop
firstWord = mid(sTextLine, iStart, (iMid - iStart)+1) end function '
Function IsAKeyword(sWord)
dim iPtr
IsAKeyword = false
for iPtr = 0 to ubound(aKeywords)
if sWord = aKeywords(iPtr) then
IsAKeyword = true
exit function
end if
next
end function
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
|