仅记录在当前日期读取错误追加到文本文件作为输出(Log read only at current d

2019-08-01 13:17发布

我看看下面保存在电子远程计算机上的文字(50个服务器的列表):\日志\ 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(今天的日期在上面的例子日期是2012年10月16日)。 如果发现任何所谓的文字“你有错误”或“错误的文件丢失。”然后输出,然后服务器名称到Excel或文本文件。

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

Answer 1:

尝试是这样的:

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


文章来源: Log read only at current date with error append to text file as output