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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script to Monitor log files

Status
Not open for further replies.

prolifix23

IS-IT--Management
Feb 13, 2007
1
US
I am trying to do this:

I have two files:
1. Application Log file
2. Txt file having search strings

I have to read the txt file get the search strings and search for them in the application log file. When a match is found I want to write the line containing the string onto a variable.
This script will run every 2 mins, so when it starts the second time it should start from where it left the first time.

Please help !!! I need this urgently. I am new to VBScript. With whatever I was able to make out I have done this.

***********************************************************
Sub Main
Option Explicit
'On Error Resume Next

Dim objFSO, objFile, objFile1, objDict, strLine

Const ForReading = 1
Const ForAppending = 8

Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("c:\temp\remaining.txt", ForAppending, True)

Set objFile = objFSO.OpenTextFile("c:\IIS.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Not objDict.Exists(strLine) Then
objDict.Add strLine, ""
End If
Loop
objFile.Close

Set objFile = objFSO.OpenTextFile("c:\IIS.log", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If objDict.Exists(strLine) Then
objfile1.writeline(strLine)
End If
Loop
objFile.Close

End Sub
***********************************************************
Please let me know how to accomplish this.

Thanks in advance.
 
objFile.Line will tell you what line it is at. If you have the script automatically loop itself every two minutes then you can store this value in a variable and start reading after the that line or if you plan on calling the script every two minutes, then maybe use another text file to keep track of that last line.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top