0

ログファイルのログ内に現在の日付が含まれているログファイルを読み取るためのヘルプを探しています。そこからすべての行を読み取り、エラーを探して現在の日付でエラーを出力したいと考えていました。

サンプル ログ ファイル

[10/12/2012 testing the app1
[10/13/2012 testing the app2
[10/14/2012 testing the app3
[10/15/2012 testing the app4

私の未完成のvbscript:

Const ForReading = 1

Dim strSearchFor

strSearchFor = "currentdate in the log file"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)

strLine = objTextFile.ReadLine

If log contains (inside mylogfile.log file the) current date then ' I am looking help to write the code here...

  Wscript.Echo "we found current date"

Else

  Wscript.Echo "We did not found current date"

End If

これで助けを探しています...たくさんありがとう....事前に...

4

2 に答える 2

1

これがPowershellのやり方です(私が書いていたときの質問にはPowershellのタグも付けられていました...)

$log = get-content c:\path\mylogfile.log

$find = $log | select-string '10/15/2012' #the date you need to find

if ($find)
{
"we found current date"
}
Else
{
"We did not found current date"
}
于 2012-10-17T07:46:16.997 に答える
1

InStr文字列内の部分文字列を検索します

Const ForReading = 1

Dim strSearchFor
strSearchFor = "currentdate in the log file"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)

do until objTextFile.AtEndOfStream
    strLine = objTextFile.ReadLine()

    If InStr(strLine, strSearchFor) <> 0 then
        Wscript.Echo "we found current date"
    Else
        Wscript.Echo "We did not found current date"
    End If
loop
objTextFile.Close
于 2012-10-17T07:39:04.623 に答える