Home All Groups Group Topic Archive Search About

grab a String (server name) from log

Author
26 Jun 2009 10:33 AM
Dee
Hi

I'm looking for a way of grabing a string from a log file and creating a
variable from it.

I have looked at the pattern match and Instr functions but non the wiser on
how I can grab a string from a log such as below:

I want to grab the name of the server between the "" in the log file

If anyone has some pointers to the code that I can use  that would be great

Log File example:

20080626093137.000000+060,1024, (MS473) Node "myserver.mycomany.com" may be
down. Failed to contact it


--
Dee

Author
26 Jun 2009 10:47 AM
Richard Mueller [MVP]
Dee wrote:

Show quoteHide quote
>
> I'm looking for a way of grabing a string from a log file and creating a
> variable from it.
>
> I have looked at the pattern match and Instr functions but non the wiser
> on
> how I can grab a string from a log such as below:
>
> I want to grab the name of the server between the "" in the log file
>
> If anyone has some pointers to the code that I can use  that would be
> great
>
> Log File example:
>
> 20080626093137.000000+060,1024, (MS473) Node "myserver.mycomany.com" may
> be
> down. Failed to contact it
>

A VBScript solution:
========
Option Explicit
Dim strLogFile, objFSO, objLog, strLine
Dim intIndex1, intIndex2, strServer

Const ForReading = 1

strLogFile = "c:\Scripts\Example.log"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.OpenTextFile(strLogFile, ForReading)

Do Until objLog.AtEndOfStream
    strLine = objLog.ReadLine
    intIndex1 = InStr(strLine, """")
    intIndex2 = InStr(intIndex1 + 1, strLine, """")
    If (intIndex1 > 0) And (intIndex2 > intIndex1) Then
        strServer = Mid(strLine, intIndex1 + 1, intIndex2 - intIndex1 - 1)
        Wscript.Echo strServer
    End If
Loop
objLog.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Author
26 Jun 2009 11:54 AM
Dee
Thanks Richard, I wil give this a go, I managed in the end to use the pattern
below in  my script which now matches between the quotes

objRE.Pattern = """.*"""

Cheers

--
Dee


Show quoteHide quote
"Richard Mueller [MVP]" wrote:

> Dee wrote:
>
> >
> > I'm looking for a way of grabing a string from a log file and creating a
> > variable from it.
> >
> > I have looked at the pattern match and Instr functions but non the wiser
> > on
> > how I can grab a string from a log such as below:
> >
> > I want to grab the name of the server between the "" in the log file
> >
> > If anyone has some pointers to the code that I can use  that would be
> > great
> >
> > Log File example:
> >
> > 20080626093137.000000+060,1024, (MS473) Node "myserver.mycomany.com" may
> > be
> > down. Failed to contact it
> >
>
> A VBScript solution:
> ========
> Option Explicit
> Dim strLogFile, objFSO, objLog, strLine
> Dim intIndex1, intIndex2, strServer
>
> Const ForReading = 1
>
> strLogFile = "c:\Scripts\Example.log"
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objLog = objFSO.OpenTextFile(strLogFile, ForReading)
>
> Do Until objLog.AtEndOfStream
>     strLine = objLog.ReadLine
>     intIndex1 = InStr(strLine, """")
>     intIndex2 = InStr(intIndex1 + 1, strLine, """")
>     If (intIndex1 > 0) And (intIndex2 > intIndex1) Then
>         strServer = Mid(strLine, intIndex1 + 1, intIndex2 - intIndex1 - 1)
>         Wscript.Echo strServer
>     End If
> Loop
> objLog.Close
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>