WillieB101
MIS
I need some help parsing text files located in multiple locations. Example:
\\server1\backup\mon\log.txt
\\server2\backup\mon\log.txt
\\server3\backup\mon\log.txt
My goal is to setup a task that runs nightly to parse all log files in the Mon folder on each server and return any failed session found. The same process would run everyday of the week Mon, Tue, Wed etc. I do have a scripe that works but only if I point it to a single file. Your help/comments would be greatly appriciated. See code below.
Code:
Const ForReading = 1
Const TriStateUseDefault = -2
strFile = "\\server1\Backups\log.txt"
arrKeyWords = Array("Failed")
strEmailFrom = "BackupAlert@mydomain.com"
strEmailTo = "me@mydomain.com"
strEmailSubject = "lines extracted from " & strFile
strSMTP = "smtp.mydomain.com"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading, False, TriStateUseDefault)
arrLines = Split(objFile.ReadAll, vbCrLf)
objFile.Close
For Each strLine in arrLines
For Each strKeyWord in arrKeyWords
If InStr(1, strLine, strKeyWord, vbTextCompare) > 0 Then
strEmailBody = strEmailBody & strLine & vbCrLf & vbCrLf
Exit For
End If
Next
Next
If strEmailBody <> "" Then
Set objEmail = CreateObject("CDO.Message")
objEmail.From = strEmailFrom
objEmail.To = strEmailTo
objEmail.Subject = strEmailSubject
objEmail.Textbody = strEmailBody
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = strSMTP
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
\\server1\backup\mon\log.txt
\\server2\backup\mon\log.txt
\\server3\backup\mon\log.txt
My goal is to setup a task that runs nightly to parse all log files in the Mon folder on each server and return any failed session found. The same process would run everyday of the week Mon, Tue, Wed etc. I do have a scripe that works but only if I point it to a single file. Your help/comments would be greatly appriciated. See code below.
Code:
Const ForReading = 1
Const TriStateUseDefault = -2
strFile = "\\server1\Backups\log.txt"
arrKeyWords = Array("Failed")
strEmailFrom = "BackupAlert@mydomain.com"
strEmailTo = "me@mydomain.com"
strEmailSubject = "lines extracted from " & strFile
strSMTP = "smtp.mydomain.com"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading, False, TriStateUseDefault)
arrLines = Split(objFile.ReadAll, vbCrLf)
objFile.Close
For Each strLine in arrLines
For Each strKeyWord in arrKeyWords
If InStr(1, strLine, strKeyWord, vbTextCompare) > 0 Then
strEmailBody = strEmailBody & strLine & vbCrLf & vbCrLf
Exit For
End If
Next
Next
If strEmailBody <> "" Then
Set objEmail = CreateObject("CDO.Message")
objEmail.From = strEmailFrom
objEmail.To = strEmailTo
objEmail.Subject = strEmailSubject
objEmail.Textbody = strEmailBody
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = strSMTP
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If