Link to home
Start Free TrialLog in
Avatar of David Regev
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("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNetwork = CreateObject("WScript.Network")
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:\Program Files\Tivoli\TSM\baclient\dsmTemp.opt", 1, True)
Set objOutputFile = objFSO.OpenTextFile("C:\Program 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.opt", True
'============================================

'


WScript.Echo "Done!"
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial