![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VB Script that searches a file for different text, with an append. I'm trying to do the following and not having much luck. I need a script that opens a text log, once opened it searches for a unique identifyer that resides near the top of the file and looks something like this: "running with process name USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only really interested in the "server55" piece, but can make due with the entire string. The script then needs to continue parsing the file for error conditions which look like this: "There is/are 1 thread(s) in total in the server that may be hung" There could be multiple instances of that error message. What I would like to do is write to a seperate file the uniqueID, pluss error message, something similiar to this: There is/are 1 thread(s) in total in the server that may be hung on server55. Any assistance would be greatly appreciated. Regards, Mike |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VB Script that searches a file for different text, with an append. "njmike" <njmike@xxxxxx> wrote in message news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx Quote: > I'm trying to do the following and not having much luck. > > I need a script that opens a text log, once opened it searches for a > unique > identifyer that resides near the top of the file and looks something like > this: > > "running with process name > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only really > interested in the "server55" piece, but can make due with the entire > string. > > The script then needs to continue parsing the file for error conditions > which look like this: > > "There is/are 1 thread(s) in total in the server that may be hung" > > There could be multiple instances of that error message. > > What I would like to do is write to a seperate file the uniqueID, pluss > error message, something similiar to this: > > There is/are 1 thread(s) in total in the server that may be hung on > server55. > > > Any assistance would be greatly appreciated. > > Regards, > > Mike > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "Pegasus (MVP)" wrote: Quote: > > "njmike" <njmike@xxxxxx> wrote in message > news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx Quote: > > I'm trying to do the following and not having much luck. > > > > I need a script that opens a text log, once opened it searches for a > > unique > > identifyer that resides near the top of the file and looks something like > > this: > > > > "running with process name > > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only really > > interested in the "server55" piece, but can make due with the entire > > string. > > > > The script then needs to continue parsing the file for error conditions > > which look like this: > > > > "There is/are 1 thread(s) in total in the server that may be hung" > > > > There could be multiple instances of that error message. > > > > What I would like to do is write to a seperate file the uniqueID, pluss > > error message, something similiar to this: > > > > There is/are 1 thread(s) in total in the server that may be hung on > > server55. > > > > > > Any assistance would be greatly appreciated. > > > > Regards, > > > > Mike > > > Let's have a look at what you've got so far. We can probably built in that. > > Appreciate your time Pegasus, Here's what I have so far: Set objFSo = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("testIn.txt") Do Until objFile.AtEndOfStream strText = objFile.ReadLine If InStr(strText, "running with process name") Then arrText = Split(strText, "and process id") strVariable = arrText(0) 'Exit Do ElseIf InStr(strText, "There is/are") Then arrText = Split(strText, "in total in the server") strVariable1 = arrText(0) Exit Do End If Loop objFile.Close Wscript.Echo strVariable Wscript.Echo strVariable1 The issue this is having is its grabbing the right server string and echoing that back, then it gets the error info - but only the first instance of it. There are multiple instances after, which I can't get it to loop to. Quote: > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "njmike" <njmike@xxxxxx> wrote in message news:A0F908A5-5F82-4581-8EFA-15BD1AF2CAA9@xxxxxx Quote: > > > "Pegasus (MVP)" wrote: > Quote: >> >> "njmike" <njmike@xxxxxx> wrote in message >> news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx Quote: >> > I'm trying to do the following and not having much luck. >> > >> > I need a script that opens a text log, once opened it searches for a >> > unique >> > identifyer that resides near the top of the file and looks something >> > like >> > this: >> > >> > "running with process name >> > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only really >> > interested in the "server55" piece, but can make due with the entire >> > string. >> > >> > The script then needs to continue parsing the file for error conditions >> > which look like this: >> > >> > "There is/are 1 thread(s) in total in the server that may be hung" >> > >> > There could be multiple instances of that error message. >> > >> > What I would like to do is write to a seperate file the uniqueID, pluss >> > error message, something similiar to this: >> > >> > There is/are 1 thread(s) in total in the server that may be hung on >> > server55. >> > >> > >> > Any assistance would be greatly appreciated. >> > >> > Regards, >> > >> > Mike >> > >> Let's have a look at what you've got so far. We can probably built in >> that. >> >> Appreciate your time Pegasus, Here's what I have so far: > Const ForReading = 1 > > Set objFSo = CreateObject("Scripting.FileSystemObject") > Set objFile = objFSO.OpenTextFile("testIn.txt") > > Do Until objFile.AtEndOfStream > strText = objFile.ReadLine > If InStr(strText, "running with process name") Then > arrText = Split(strText, "and process id") > strVariable = arrText(0) > 'Exit Do > ElseIf InStr(strText, "There is/are") Then > arrText = Split(strText, "in total in the server") > strVariable1 = arrText(0) > Exit Do > End If > Loop > > objFile.Close > > Wscript.Echo strVariable > Wscript.Echo strVariable1 > > The issue this is having is its grabbing the right server string and > echoing > that back, then it gets the error info - but only the first instance of > it. > There are multiple instances after, which I can't get it to loop to. > vague. Here are some questions: - In your initial post you mention a "UniqueID". What ID might this be? - How many server identifier lines are there? Just the one? What if there isn't one? What if there is more than one? - Do you want to write each instance of a hung process to the console or do you want to count them, then write a single summary line? - If you want to process the whole file, why do you have an "exit do" in your code? |
My System Specs![]() |
| | #5 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "Pegasus (MVP)" wrote: Quote: > > "njmike" <njmike@xxxxxx> wrote in message > news:A0F908A5-5F82-4581-8EFA-15BD1AF2CAA9@xxxxxx Quote: > > > > > > "Pegasus (MVP)" wrote: > > Quote: > >> > >> "njmike" <njmike@xxxxxx> wrote in message > >> news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx > >> > I'm trying to do the following and not having much luck. > >> > > >> > I need a script that opens a text log, once opened it searches for a > >> > unique > >> > identifyer that resides near the top of the file and looks something > >> > like > >> > this: > >> > > >> > "running with process name > >> > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only really > >> > interested in the "server55" piece, but can make due with the entire > >> > string. > >> > > >> > The script then needs to continue parsing the file for error conditions > >> > which look like this: > >> > > >> > "There is/are 1 thread(s) in total in the server that may be hung" > >> > > >> > There could be multiple instances of that error message. > >> > > >> > What I would like to do is write to a seperate file the uniqueID, pluss > >> > error message, something similiar to this: > >> > > >> > There is/are 1 thread(s) in total in the server that may be hung on > >> > server55. > >> > > >> > > >> > Any assistance would be greatly appreciated. > >> > > >> > Regards, > >> > > >> > Mike > >> > > >> > >> Let's have a look at what you've got so far. We can probably built in > >> that. > >> > >> Appreciate your time Pegasus, Here's what I have so far: > > Const ForReading = 1 > > > > Set objFSo = CreateObject("Scripting.FileSystemObject") > > Set objFile = objFSO.OpenTextFile("testIn.txt") > > > > Do Until objFile.AtEndOfStream > > strText = objFile.ReadLine > > If InStr(strText, "running with process name") Then > > arrText = Split(strText, "and process id") > > strVariable = arrText(0) > > 'Exit Do > > ElseIf InStr(strText, "There is/are") Then > > arrText = Split(strText, "in total in the server") > > strVariable1 = arrText(0) > > Exit Do > > End If > > Loop > > > > objFile.Close > > > > Wscript.Echo strVariable > > Wscript.Echo strVariable1 > > > > The issue this is having is its grabbing the right server string and > > echoing > > that back, then it gets the error info - but only the first instance of > > it. > > There are multiple instances after, which I can't get it to loop to. > > > This looks like a pretty good start. However, your job spec is a little > vague. Here are some questions: > - In your initial post you mention a "UniqueID". What ID > might this be? > - How many server identifier lines are there? Just the one? What > if there isn't one? What if there is more than one? > - Do you want to write each instance of a hung process to the > console or do you want to count them, then write a single > summary line? > - If you want to process the whole file, why do you have an > "exit do" in your code? > > > Again - your time is appreciated. I'll try to clarify.. vague. Here are some questions: Q. In your initial post you mention a "UniqueID". What ID might this be? A. I call it a unique Id, but its really a substring of the following line of text in the log: "running with process name USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" The uniqueID, is actually the text "server55" which corresponds to a VM guest, running WAS - two per host, with a total of 47 hosts - so that uniqueID will actually be anything from server1 to server94. Q. How many server identifier lines are there? Just the one? What if there isn't one? What if there is more than one? A. Each log will have only one ID line in it. If there is not one, it can be assumed there is some sort of error condition and the text for that variable should read "unkonwn server" There should never be more than one, if there is though, they will be dupes. Q. Do you want to write each instance of a hung process to the console or do you want to count them, then write a single summary line? A.I would like to write each out to a summary file - which will be monitored by OVO and alert our service desk of a possible issue. Q. If you want to process the whole file, why do you have an "exit do" in your code? A. Good question.. Its due to inexperience with VBS.. let me try removing it. Regards, Mike |
My System Specs![]() |
| | #6 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "njmike" <njmike@xxxxxx> wrote in message news:FD9C14EF-95F1-4959-9745-D2060E56FC00@xxxxxx Quote: > > > "Pegasus (MVP)" wrote: > Quote: >> >> "njmike" <njmike@xxxxxx> wrote in message >> news:A0F908A5-5F82-4581-8EFA-15BD1AF2CAA9@xxxxxx Quote: >> > >> > >> > "Pegasus (MVP)" wrote: >> > >> >> >> >> "njmike" <njmike@xxxxxx> wrote in message >> >> news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx >> >> > I'm trying to do the following and not having much luck. >> >> > >> >> > I need a script that opens a text log, once opened it searches for a >> >> > unique >> >> > identifyer that resides near the top of the file and looks something >> >> > like >> >> > this: >> >> > >> >> > "running with process name >> >> > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only >> >> > really >> >> > interested in the "server55" piece, but can make due with the entire >> >> > string. >> >> > >> >> > The script then needs to continue parsing the file for error >> >> > conditions >> >> > which look like this: >> >> > >> >> > "There is/are 1 thread(s) in total in the server that may be hung" >> >> > >> >> > There could be multiple instances of that error message. >> >> > >> >> > What I would like to do is write to a seperate file the uniqueID, >> >> > pluss >> >> > error message, something similiar to this: >> >> > >> >> > There is/are 1 thread(s) in total in the server that may be hung on >> >> > server55. >> >> > >> >> > >> >> > Any assistance would be greatly appreciated. >> >> > >> >> > Regards, >> >> > >> >> > Mike >> >> > >> >> >> >> Let's have a look at what you've got so far. We can probably built in >> >> that. >> >> >> >> Appreciate your time Pegasus, Here's what I have so far: >> > >> > Const ForReading = 1 >> > >> > Set objFSo = CreateObject("Scripting.FileSystemObject") >> > Set objFile = objFSO.OpenTextFile("testIn.txt") >> > >> > Do Until objFile.AtEndOfStream >> > strText = objFile.ReadLine >> > If InStr(strText, "running with process name") Then >> > arrText = Split(strText, "and process id") >> > strVariable = arrText(0) >> > 'Exit Do >> > ElseIf InStr(strText, "There is/are") Then >> > arrText = Split(strText, "in total in the server") >> > strVariable1 = arrText(0) >> > Exit Do >> > End If >> > Loop >> > >> > objFile.Close >> > >> > Wscript.Echo strVariable >> > Wscript.Echo strVariable1 >> > >> > The issue this is having is its grabbing the right server string and >> > echoing >> > that back, then it gets the error info - but only the first instance of >> > it. >> > There are multiple instances after, which I can't get it to loop to. >> > >> This looks like a pretty good start. However, your job spec is a little >> vague. Here are some questions: >> - In your initial post you mention a "UniqueID". What ID >> might this be? >> - How many server identifier lines are there? Just the one? What >> if there isn't one? What if there is more than one? >> - Do you want to write each instance of a hung process to the >> console or do you want to count them, then write a single >> summary line? >> - If you want to process the whole file, why do you have an >> "exit do" in your code? >> >> >> Again - your time is appreciated. I'll try to clarify.. > This looks like a pretty good start. However, your job spec is a little > vague. Here are some questions: > > > > Q. In your initial post you mention a "UniqueID". What ID > might this be? > A. I call it a unique Id, but its really a substring of the following line > of text in the log: > > "running with process name > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" > The uniqueID, is actually the text "server55" which corresponds to a VM > guest, running WAS - two per host, with a total of 47 hosts - so that > uniqueID will actually be anything from server1 to server94. > > > Q. How many server identifier lines are there? Just the one? What > if there isn't one? What if there is more than one? > A. Each log will have only one ID line in it. If there is not one, it can > be assumed there is some sort of error condition and the text for that > variable should read "unkonwn server" There should never be more than > one, > if there is though, they will be dupes. > > > > > Q. Do you want to write each instance of a hung process to the > console or do you want to count them, then write a single > summary line? > A.I would like to write each out to a summary file - which will be > monitored > by OVO and alert our service desk of a possible issue. > > > > Q. If you want to process the whole file, why do you have an > "exit do" in your code? > A. Good question.. Its due to inexperience with VBS.. let me try removing > it. > > Regards, > > Mike > much the same as your own. Note that I did not test it. Const ForReading = 1 ServerID = "(unknown server)" Set objFSo = CreateObject("Scripting.FileSystemObject") '***Set objFile = objFSo.OpenTextFile("testIn.txt") Set objFile = objFSo.OpenTextFile("c:\testIn.txt") Do Until objFile.AtEndOfStream strText = objFile.ReadLine 'If InStr(strText, "running with process name") Then If InStr(strText, "running with process name") > 0 Then 'arrText = Split(strText, "and process id") 'strVariable = arrText(0) ServerID = Split(strText, "and process id")(0) 'Exit Do (why?) End If If InStr(strText, "There is/are") Then 'arrText = Split(strText, "in total in the server") 'strVariable1 = arrText(0) WScript.Echo Split(strText, "in total in the server")(0) _ & " on "& ServerID End If Loop objFile.Close Comments: Line2: Here we preset the server name, in case it's not defined in your text file. Line6: If you want your scripts to be robust then you MUST fully qualify each file name with drive & folder name. Line11: The instr function returns a number reflecting the position where the search string was found. If not found then it returns 0. Your code should reflect this. Line14: You can combine the two preceding lines into a single line of code. Line15: Don't exit if you want to process the whole file! Line20: You should write each instance of a hung process to the console. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "Pegasus (MVP)" wrote: Quote: > > "njmike" <njmike@xxxxxx> wrote in message > news:FD9C14EF-95F1-4959-9745-D2060E56FC00@xxxxxx Quote: > > > > > > "Pegasus (MVP)" wrote: > > Quote: > >> > >> "njmike" <njmike@xxxxxx> wrote in message > >> news:A0F908A5-5F82-4581-8EFA-15BD1AF2CAA9@xxxxxx > >> > > >> > > >> > "Pegasus (MVP)" wrote: > >> > > >> >> > >> >> "njmike" <njmike@xxxxxx> wrote in message > >> >> news:A0DC18CE-BF54-4C1E-A78F-32D7A4676F22@xxxxxx > >> >> > I'm trying to do the following and not having much luck. > >> >> > > >> >> > I need a script that opens a text log, once opened it searches for a > >> >> > unique > >> >> > identifyer that resides near the top of the file and looks something > >> >> > like > >> >> > this: > >> >> > > >> >> > "running with process name > >> >> > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" (I'm only > >> >> > really > >> >> > interested in the "server55" piece, but can make due with the entire > >> >> > string. > >> >> > > >> >> > The script then needs to continue parsing the file for error > >> >> > conditions > >> >> > which look like this: > >> >> > > >> >> > "There is/are 1 thread(s) in total in the server that may be hung" > >> >> > > >> >> > There could be multiple instances of that error message. > >> >> > > >> >> > What I would like to do is write to a seperate file the uniqueID, > >> >> > pluss > >> >> > error message, something similiar to this: > >> >> > > >> >> > There is/are 1 thread(s) in total in the server that may be hung on > >> >> > server55. > >> >> > > >> >> > > >> >> > Any assistance would be greatly appreciated. > >> >> > > >> >> > Regards, > >> >> > > >> >> > Mike > >> >> > > >> >> > >> >> Let's have a look at what you've got so far. We can probably built in > >> >> that. > >> >> > >> >> Appreciate your time Pegasus, Here's what I have so far: > >> > > >> > Const ForReading = 1 > >> > > >> > Set objFSo = CreateObject("Scripting.FileSystemObject") > >> > Set objFile = objFSO.OpenTextFile("testIn.txt") > >> > > >> > Do Until objFile.AtEndOfStream > >> > strText = objFile.ReadLine > >> > If InStr(strText, "running with process name") Then > >> > arrText = Split(strText, "and process id") > >> > strVariable = arrText(0) > >> > 'Exit Do > >> > ElseIf InStr(strText, "There is/are") Then > >> > arrText = Split(strText, "in total in the server") > >> > strVariable1 = arrText(0) > >> > Exit Do > >> > End If > >> > Loop > >> > > >> > objFile.Close > >> > > >> > Wscript.Echo strVariable > >> > Wscript.Echo strVariable1 > >> > > >> > The issue this is having is its grabbing the right server string and > >> > echoing > >> > that back, then it gets the error info - but only the first instance of > >> > it. > >> > There are multiple instances after, which I can't get it to loop to. > >> > > >> > >> This looks like a pretty good start. However, your job spec is a little > >> vague. Here are some questions: > >> - In your initial post you mention a "UniqueID". What ID > >> might this be? > >> - How many server identifier lines are there? Just the one? What > >> if there isn't one? What if there is more than one? > >> - Do you want to write each instance of a hung process to the > >> console or do you want to count them, then write a single > >> summary line? > >> - If you want to process the whole file, why do you have an > >> "exit do" in your code? > >> > >> > >> Again - your time is appreciated. I'll try to clarify.. > > This looks like a pretty good start. However, your job spec is a little > > vague. Here are some questions: > > > > > > > > Q. In your initial post you mention a "UniqueID". What ID > > might this be? > > A. I call it a unique Id, but its really a substring of the following line > > of text in the log: > > > > "running with process name > > USSECAVDMPAPP1Cell01\USSECAVDMPAPP28Node01\server55" > > The uniqueID, is actually the text "server55" which corresponds to a VM > > guest, running WAS - two per host, with a total of 47 hosts - so that > > uniqueID will actually be anything from server1 to server94. > > > > > > Q. How many server identifier lines are there? Just the one? What > > if there isn't one? What if there is more than one? > > A. Each log will have only one ID line in it. If there is not one, it can > > be assumed there is some sort of error condition and the text for that > > variable should read "unkonwn server" There should never be more than > > one, > > if there is though, they will be dupes. > > > > > > > > > > Q. Do you want to write each instance of a hung process to the > > console or do you want to count them, then write a single > > summary line? > > A.I would like to write each out to a summary file - which will be > > monitored > > by OVO and alert our service desk of a possible issue. > > > > > > > > Q. If you want to process the whole file, why do you have an > > "exit do" in your code? > > A. Good question.. Its due to inexperience with VBS.. let me try removing > > it. > > > > Regards, > > > > Mike > > > OK, this makes it much clearer. Please have a look at the code below. It's > much the same as your own. Note that I did not test it. > Const ForReading = 1 > ServerID = "(unknown server)" > > Set objFSo = CreateObject("Scripting.FileSystemObject") > '***Set objFile = objFSo.OpenTextFile("testIn.txt") > Set objFile = objFSo.OpenTextFile("c:\testIn.txt") > > Do Until objFile.AtEndOfStream > strText = objFile.ReadLine > 'If InStr(strText, "running with process name") Then > If InStr(strText, "running with process name") > 0 Then > 'arrText = Split(strText, "and process id") > 'strVariable = arrText(0) > ServerID = Split(strText, "and process id")(0) > 'Exit Do (why?) > End If > If InStr(strText, "There is/are") Then > 'arrText = Split(strText, "in total in the server") > 'strVariable1 = arrText(0) > WScript.Echo Split(strText, "in total in the server")(0) _ > & " on "& ServerID > End If > Loop > > objFile.Close > > Comments: > Line2: Here we preset the server name, in case it's > not defined in your text file. > Line6: If you want your scripts to be robust then you MUST > fully qualify each file name with drive & folder name. > Line11: The instr function returns a number reflecting the position > where the search string was found. If not found then it > returns 0. Your code should reflect this. > Line14: You can combine the two preceding lines into a > single line of code. > Line15: Don't exit if you want to process the whole file! > Line20: You should write each instance of a hung process > to the console. > > > Pegasus, Regards, Mike |
My System Specs![]() |
| | #8 (permalink) |
| | Re: VB Script that searches a file for different text, with an app "njmike" <njmike@xxxxxx> wrote in message news:168120DC-E2B0-4951-83AA-8E8E6C03C47E@xxxxxx Quote: > > Pegasus, > It worked perfectly. Going to do some testing on it. > Regards, > Mike > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Append Date to NTBackup Log File | VB Script | |||
| Append text to top of text file? | PowerShell | |||
| Need help with log ( text ) file - write vs append | VB Script | |||
| exporting results/text of powershell script to a file as it is run | PowerShell | |||
| output .ps1 script to text file | PowerShell | |||