0

嗨脚本专家....

在下面的代码中寻找您的帮助....RemoteServersList.Txt,我想调用每个系统,如 \RemoteServerName\E$\V2\log.Txt 我缺少几行代码......

请帮助我....非常感谢....

Set Fso = CreateObject("Scripting.FileSystemObject")

Set InFile = fso.OpenTextFile("RemoteServersList.Txt")

Const ForReading = 1

Do While Not (InFile.atEndOfStream)

strComputer = InFile.ReadLine


today = Date()

Set fso = CreateObject("Scripting.FileSystemObject")


strFilePath = "\\" & strComputer & "\E$\V2\" ' This is wrong 'here I am missing a 'code.. looking for your help

Set InputFile = fso.OpenTextFile("strFilePath\log.txt", 1)  ' This is wrong here I am 'missing a code.. looking for your help


Set out = fso.OpenTextFile("error.log", 2)

    Do Until InputFile.AtEndOfStream
      line = InputFile.ReadLine
      If Left(line, Len(today)+1) = "[" & today Then

    WScript.Echo "Hello" ' I need to append this to output file
    out.WriteLine line & vbTab & InputFile.ReadLine & vbTab & strComputer


            If InStr(line, "error") > 0 Then
        ' line contains "error"
        out.WriteLine line & vbTab & InputFile.ReadLine & vbTab & strComputer

        End If
    End If


    Loop

InputFile.Close
out.Close


Loop
4

1 回答 1

1

RemoteServerList.txt 是一个包含服务器列表的 txt 文件,写成这样:

server-1
server-2
server-3
etc.

在每台服务器上,您必须阅读此文本文件:

\\server-1\e$\V2\log.txt
\\server-2\e$\V2\log.txt

?

我在您的代码中看到的第一个问题是字符串分配,这应该是正确的:

strFilePath = "\\" & strComputer & "\E$\V2\"
Set InputFile = fso.OpenTextFile(strFilePath & "log.txt", 1)

但是你想在哪里写 error.log 文件?本地或远程机器上?

如果您想在本地计算机上使用它,最好只打开一次文件,在脚本的开头,就在 Set Inifile 下方。

如果文件不存在,您必须使用CreateTextFile或使用fso.OpenTextFile("error.log", 2, True)打开它:

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InFile = fso.OpenTextFile("RemoteServersList.Txt")
Set out = fso.CreateTextFile("error.log")

Const ForReading = 1

Do While Not (InFile.atEndOfStream)
  strComputer = InFile.ReadLine
  today = Date()
  Set fso = CreateObject("Scripting.FileSystemObject")
  strFilePath = "\\" & strComputer & "\E$\V2\"

  Set InputFile = fso.OpenTextFile(strFilePath & "log.txt", 1)
  Do Until InputFile.AtEndOfStream

    If (condition) Then
      out.WriteLine [write something to output file]
    End If

  Loop
  InputFile.close

Loop

out.Close
InFile.Close
于 2012-10-19T10:09:52.190 回答