问题
I Have below text on remote computers (a list of 50 servers) saved in e:\logs\action.log This action.log will contain the a Date & time and every time a action performed will be tracked and appends the date & time..... and the next line will have the action associated like working, not working...
Sample action.log file text.....
[10/15/2012 09:33:56:248 qwe rtd] {some text will be there here}
this time it is working on the task and taken: 2.31 seconds
[10/15/2012 09:34:55:248 qwe rtd] {some text will be there here}
this time it is working on the task and taken: 3.31 seconds
[10/16/2012 09:33:56:248 qwe rtd] {some text will be there here}
this time it is working on the task and taken: 2.31 seconds
[10/16/2012 09:34:55:248 qwe rtd] {some text will be there here}
this time it is working on the task and taken: 3.31 seconds
[10/16/2012 09:34:55:248 qwe rtd] {you got error}
You got error as file missing..
The script I am looking for a script to read the action.log from the current date (todays date in the above example date is 10/16/2012). And if found any text called "you got error" or "error as file missing.." then output followed by server Name to a excel or a text file.
(the Basic criteria is to search on current date text only.... as past errors are not valid...) Looking for some script from forum.... I am a new to scripting......
回答1:
Try something like this:
computer = CreateObject("WScript.Network").ComputerName
today = Right("0" & Month(Date), 2) & "/" & Right("0", Day(Date), 2) & "/" _
& Year(Date)
Set fso = CreateObject("Scripting.FileSystemObject")
Set in = fso.OpenTextFile("action.log", 1)
Set out = fso.OpenTextFile("error.log", 2)
Do Until in.AtEndOfStream
line = in.ReadLine
If Left(line, Len(today)+1) = "[" & today Then
' line timestamped with today's date
If InStr(line, "error") > 0 Then
' line contains "error"
out.WriteLine line & vbTab & in.ReadLine & vbTab & computer
End If
End If
Loop
in.Close
out.Close
来源:https://stackoverflow.com/questions/12926168/log-read-only-at-current-date-with-error-append-to-text-file-as-output