I saw a couple of questions about a script searching for a word in a logfile and then create a event with the line including the “word” but also the two lines before that. This script search for the word “Warning” in the file logfile.txt. If found it will generate a local event with the line includning Warning but also the two lines before that.
Const ForReading = 1
Const EVENT_WARNING = 2Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "Warning"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("logfile.txt", ForReading)
strLineNo = 1
Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)
   strCacheC = strCacheB
  strCacheB = strCacheA
  strCacheA = strSearchString
  Â
 If colMatches.Count > 0 Then
       For Each strMatch in colMatches Â
         Â
 Set objShell = CreateObject("Wscript.Shell")
 objShell.LogEvent EVENT_WARNING, _
 "Warning from logfile: " & vbCr &_
 "BEGINNING OF LINES" & vbCr &_
 "" & vbCr &_
 strCacheC & vbCr &_
        strCacheB & vbCr &_
        strCacheA & vbCr &_
 "" & vbCr &_
        "END OF LINES."
       Next
 End If  Â
strLineNo = strLineNo + 1
Loop
objFile.Close
[…] As you can see, it is normal FTP commands inside that file. If you want to only test download a file from a FTP and dont want to check the ftp_log.txt file, you can check when the downloaded file was last updated, according to this post. You can also use this script to search your logfile for words, and generate events. […]