Hi, does anyone have a VBScript that will search a logfile for specific errors and then email these errors using SMTP either as text data or a new attached file?
This may be of interest for you: thread329-735716
Feel free to do a keyword search in this forum for FileSystemObject or fso (for the logfile issue), and for smtp or mail (for the email issue)
' DATE : 1/28/2004
'
' COMMENT: Searches a log file for specific text
'
'==========================================================================
Dim oFSO
ForReading = 1
Set oFSO=CreateObject("Scripting.FileSystemObject"
'Set the log file path here
logFile = "C:\Test.log"
' Set the value of what you are looking for here.
SearchText = "Test2"
'Read the text file
MyList= ofspenTextFile(logFile, ForReading).ReadAll
'Now make it an array so we can check each line
myArray=Split(MyList,vbCrLf, -1, vbtextcompare)
'Here we step through each array element and check for your values
For Each Val In myArray
'Don't know where the text might be in the line so check everywhere
ValLength = Len(Val)
For valLoop = 1 To ValLength
If Mid(Val,valLoop,Len(searchText)) = SearchText Then
'Insert your code for emailing what you want here.
MsgBox "Got it!"
End If
Next
Next
The error is saying that it can't find the log file. Did you edit the path?
Refer to the script above for this text:
'Set the log file path here
logFile = "C:\Test.log"
I have it currently set to search a log file named C:\Test.log.
Note that it will be looking for the text "Test2" as indicated in the code:
' Set the value of what you are looking for here.
SearchText = "Test2"
Either edit the log name and path and the desired search text, or create a log file called Test.log and put a line it it somewhere with the text Test2. Run the script with this text and without. With it it is set to give a message box that says Got It. Without it will do nothing as I assumed you did not want the server sending anything if there were no errors.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.