1

我在远程计算机上有以下文本(50 个服务器的列表)保存在 e:\logs\action.log 这个 action.log 将包含一个日期和时间,每次执行的操作都会被跟踪并附加日期和时间.....下一行将有相关的动作,比如工作,不工作......

示例 action.log 文件文本.....

[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..

我正在寻找一个脚本来从当前日期读取 action.log 的脚本(上面示例日期中的今天日期是 10/16/2012)。如果发现任何文本称为“你有错误”或“文件丢失错误..”然后输出后跟服务器名称到 excel 或文本文件。

(基本标准是仅搜索当前日期文本......因为过去的错误无效......)从论坛寻找一些脚本......我是脚本的新手......

4

1 回答 1

0

尝试这样的事情:

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
于 2012-10-17T09:06:59.480 回答