« Previous Next »

Thread: Executing log parser query in vbscript?

Last post 12-22-2008 9:32 PM by Hitchheik. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 12-11-2008, 9:42 AM

    Executing log parser query in vbscript?

    Hello,

    I am new to using LogParser, and I first have to say that it is a very very powerful tool! I have been tasked with filtering out certain things from my IIS log file and outputting it into a new log file in the same format (W3C). I have come up with the correct query, but I now need to find a way to run it from inside a vbscript. Does anyone have examples of running a log parser query in vbscript? Below is the query that I have written:

    LogParser -i:IISW3C -o:W3C "select date, time, s-sitename, s-computername, s-ip, cs-method, cs-uri-stem, cs-uri-query, s-port, cs-username, c-ip, cs(User-Agent), cs(Cookie), cs(Referer), cs-host, sc-status, sc-substatus, sc-win32-status, time-taken FROM c:\temp\logs\ex*.log WHERE cs(Referer) NOT LIKE '%weblink%' AND cs-uri-stem NOT LIKE '%/left1_%' and cs-uri-stem NOT LIKE '%pngbehavior%'" -rtp:-1 >> c:\temp\soalogs\scrub-ex<date>.log

     Any help is greatly appreciated!

    Thanks,

    Sheel Shah

  • 12-11-2008, 2:06 PM In reply to

    • ksingla
    • Top 25 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 863

    Re: Executing log parser query in vbscript?

    Here is the vbscript example available in logparser.chm (do regsvr32 logparser.dll to register com component).

    Dim oLogQuery
    Dim oIISW3CInputFormat
    Dim strQuery
    Dim oRecordSet
    Dim oRecord
    Dim strClientIp

    Set oLogQuery = CreateObject("MSUtil.LogQuery")

    ' Create Input Format object
    Set oIISW3CInputFormat = CreateObject("MSUtil.LogQuery.IISW3CInputFormat")

    ' Create query text
    strQuery = "SELECT c-ip FROM <1> WHERE cs-uri-stem LIKE '%hitcount.asp'"

    ' Execute query and receive a LogRecordSet
    Set oRecordSet = oLogQuery.Execute ( strQuery, oIISW3CInputFormat )

    ' Visit all records
    DO WHILE NOT oRecordSet.atEnd

    ' Get a record
    Set oRecord = oRecordSet.getRecord

    ' Get first field value
    strClientIp = oRecord.getValue ( 0 )

    ' Print field value
    WScript.Echo "Client IP Address: " & strClientIp

    ' Advance LogRecordSet to next record
    oRecordSet.moveNext

    LOOP

    ' Close RecordSet
    oRecordSet.close

    Hope this helps.
    Kanwal

    Follow me on twitter at http://twitter.com/kjsingla
  • 12-22-2008, 9:32 PM In reply to

    Re: Executing log parser query in vbscript?

     I have an easy template system that I use.  There are a number of differences that you need to learn for the input and output factors especially when doing XML or HTML formating.  Here is your SQL in VBS format. remember to save as .vbs

     

    '===================================================================================
    '************************** Set Input and Output formats  ******************************
    Set objLogParser = CreateObject("MSUtil.LogQuery")
    Set objInputFormat = CreateObject("MSUtil.LogQuery.IISW3CInputFormat")
    Set objOutputFormat = CreateObject("MSUtil.LogQuery.W3COutputFormat")
    '===================================================================================
    '********************************* Set String inputs  **********************************
    strDate = Replace(Date,"/","-")
    outputfile = "c:\temp\soalogs\scrub-ex" & strDate & ".log"
    '===================================================================================
    '******************************** Insert Query here  **********************************
    strQuery = "select date, time, s-sitename, s-computername, s-ip, cs-method, cs-uri-stem, cs-uri-query, s-port, cs-username, c-ip, cs(User-Agent), cs(Cookie), cs(Referer), cs-host, sc-status, sc-substatus, sc-win32-status, time-taken FROM c:\temp\logs\ex*.log WHERE cs(Referer) NOT LIKE '%weblink%' AND cs-uri-stem NOT LIKE '%/left1_%' and cs-uri-stem NOT LIKE '%pngbehavior%'"
    '===================================================================================
    '******************************** This calls the job   **********************************
    objLogParser.ExecuteBatch strQuery, objInputFormat, objOutputFormat
    '===================================================================================
    '*************************** Open file to read ****************************************
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    objShell.Run outputfile

    '**************************************************************************************

     you do not need the Open file section except to make sure it works.

     Jerome

Page 1 of 1 (3 items)
Microsoft Communities