日志在当前日期只读,错误附加到文本文件作为输出 [英] Log read only at current date with error append to text file as output

查看:13
本文介绍了日志在当前日期只读,错误附加到文本文件作为输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 e:logsaction.log 中保存了远程计算机上的以下文本(50 个服务器的列表)此 action.log 将包含日期 &时间和每次执行的操作都将被跟踪并附加日期和时间.时间..... 下一行将有动作关联喜欢工作,不工作...

I Have below text on remote computers (a list of 50 servers) saved in e:logsaction.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...

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

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

我正在寻找一个脚本来从当前日期读取 action.log(上面示例中的今天日期是 2012 年 10 月 16 日).如果发现任何名为you got error"或error as file missing.."的文本,则输出后跟服务器名称到 excel 或文本文件.

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

推荐答案

试试这个:

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

这篇关于日志在当前日期只读,错误附加到文本文件作为输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆