Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

smtp email of log file errors

Status
Not open for further replies.

vbcdor

Technical User
Jan 27, 2004
39
US
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)

Hope This Help
PH.
 
'==========================================================================
'
' NAME: SearchLogFile.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' 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= ofso_OpenTextFile(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
 
Hi Markdmac,

I tried your script and I get the following error message:

Script: c:\temp\logsearch.vbs
Line: 23
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error

When I goto line 23 I find the following:

MyList= oFSO.OpenTextFile(logFile, ForReading).ReadAll

I'm not sure what is wrong with this statement.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top