|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
grab a String (server name) from logI'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 Dee wrote:
Show quoteHide quote > A VBScript solution:> 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 > ======== 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 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 -- Show quoteHide quoteDee "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 > -- > > >
Scripting Language
DNS suffix search list... Robocopy - not providing destination in log output issue on scripting syntax on x64 auto add sutdents to AD 2008 WMI & Eventlogs Finding password protected files How to make goto when nowhere to go ? Script to diable the C:$ share Send to Compressed Folder missing for limited users on XP Pro |
|||||||||||||||||||||||