Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why the loop can not be executed for the 2nd time? 1

Status
Not open for further replies.

aiqin

Programmer
Jan 3, 2018
3
0
0
AU
#$language = "VBScript"
#$interface = "1.0"

Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const passwd = "xxx_2017"
Dim fso,file1,line,str1,params
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso_OpenTextFile("c:\xxx\config.txt",Forreading, False)
crt.Screen.Synchronous = False
DO While file1.AtEndOfStream <> True
'read every line
line = file1.ReadLine
crt.Screen.Send line & vbcr
'ip,passwd,en passwd
params = Split (line)
crt.Screen.Send params(0) & vbcr
' 'ssh
crt.Screen.Send "ssh " & params(0) & vbcr
'passwd
crt.Screen.WaitForString "Password:"
crt.Screen.Send passwd & vbcr
'en
crt.Screen.WaitForString "v>"
crt.Screen.Send "enable" & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send passwd & vbcr
crt.Screen.waitForString "#"
'commands
cmd1 = "sh ip int bri"
cmd2 = "show track"
'str1 = str1 & "backup(" & params(0) &")" & ".cfg"
crt.Screen.Send cmd1 & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send cmd2 & vbcr
crt.Screen.Send "exit " & vbcr
Loop
'crt.Screen.Synchronous = False
End Sub

the script can only execute for the 1st loop.
it will never read the 2nd line of the file and do ssh to the router?
but if I ' from the 19th line, then it's okay to have the content of the file to be printed on the screen.
Why?

Thanks a lot.
 
What happens when you send params(0) before you send "ssh " & params(0)
 
...nevermind my comment above, coffee didn't settle in yet.

Maybe the line below is causing the whole script to exit?
crt.Screen.Send "exit " & vbcr
 
hi, Guitarzan

Seems it is!
if I "'" the line with "exit" then I can have the 2nd of loop running.
but I really need the exit to quit the 1st router.
then what can I do? [evil]
 
I have tried
exit
quit
logout
to exit the router, but none of them can have the 2nd loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top