David Regev
asked on
vb script Read and write to file
hi
i write a little script that read from file base on "NODENAME" and "TCPSERVERADDRESS"
the TCPSERVERADDRESS will write base on ping success
the node name section is work just fine
but the TCPSERVERADDRESS do nothing
Thx
David
Option Explicit
Dim strComputer
Dim objShell, objFSO , wshNetwork
Dim objInputFile, objOutputFile, strLine
Dim strTarget, strPingResults ,ping
strComputer = "."
Set objShell = Wscript.CreateObject("Wscr ipt.Shell" )
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set wshNetwork = CreateObject("WScript.Netw ork")
Set Ping = objShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strTarget = "10.0.0.2" 'IP address or hostname
Set Ping = objShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs Each
Set objInputFile = objFSO.OpenTextFile("C:\Pr ogram Files\Tivoli\TSM\baclient\ dsmTemp.op t", 1, True)
Set objOutputFile = objFSO.OpenTextFile("C:\Pr ogram Files\Tivoli\TSM\baclient\ dsm.opt", 2, True)
Do Until objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
If Left(strLine, 8) = "NODENAME" Then
strLine = Left(strLine, 8) & " " & WshNetwork.ComputerName
objOutputFile.Writeline strLine
Else
objOutputFile.Writeline strLine
End If
strPingResults = LCase(Ping.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
If Left(strLine, 16) = "TCPSERVERADDRESS" Then
strLine = Left(strLine, 16) & " " & "Test"
objOutputFile.Writeline strLine
Else
objOutputFile.Writeline strLine
End If
End If
'objInputFile.Close
'objOutputFile.Close
Loop
'strPingResults = LCase(Ping.StdOut.ReadAll)
'If InStr(strPingResults, "reply from") Then
'If Left(strLine, 17) = "TCPSERVERADDRESS" Then
'strLine = Left(strLine, 16) & " " & WshNetwork.ComputerName
'objOutputFile.Writeline strLine
'Else
'objOutputFile.Writeline strLine
'End If
'End If
'Loop
'objInputFile.Close
'objOutputFile.Close
'objFSO.DeleteFile "C:\Program Files\Tivoli\TSM\baclient\ dsmTemp.op t", True
'========================= ========== =========
'
WScript.Echo "Done!"
i write a little script that read from file base on "NODENAME" and "TCPSERVERADDRESS"
the TCPSERVERADDRESS will write base on ping success
the node name section is work just fine
but the TCPSERVERADDRESS do nothing
Thx
David
Option Explicit
Dim strComputer
Dim objShell, objFSO , wshNetwork
Dim objInputFile, objOutputFile, strLine
Dim strTarget, strPingResults ,ping
strComputer = "."
Set objShell = Wscript.CreateObject("Wscr
Set objFSO = CreateObject("Scripting.Fi
Set wshNetwork = CreateObject("WScript.Netw
Set Ping = objShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strTarget = "10.0.0.2" 'IP address or hostname
Set Ping = objShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs Each
Set objInputFile = objFSO.OpenTextFile("C:\Pr
Set objOutputFile = objFSO.OpenTextFile("C:\Pr
Do Until objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
If Left(strLine, 8) = "NODENAME" Then
strLine = Left(strLine, 8) & " " & WshNetwork.ComputerName
objOutputFile.Writeline strLine
Else
objOutputFile.Writeline strLine
End If
strPingResults = LCase(Ping.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
If Left(strLine, 16) = "TCPSERVERADDRESS" Then
strLine = Left(strLine, 16) & " " & "Test"
objOutputFile.Writeline strLine
Else
objOutputFile.Writeline strLine
End If
End If
'objInputFile.Close
'objOutputFile.Close
Loop
'strPingResults = LCase(Ping.StdOut.ReadAll)
'If InStr(strPingResults, "reply from") Then
'If Left(strLine, 17) = "TCPSERVERADDRESS" Then
'strLine = Left(strLine, 16) & " " & WshNetwork.ComputerName
'objOutputFile.Writeline strLine
'Else
'objOutputFile.Writeline strLine
'End If
'End If
'Loop
'objInputFile.Close
'objOutputFile.Close
'objFSO.DeleteFile "C:\Program Files\Tivoli\TSM\baclient\
'=========================
'
WScript.Echo "Done!"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.