INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
#$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.

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

What happens when you send params(0) before you send "ssh " & params(0)

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

Does "c:\xxx\config.txt" only have one line?

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

...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

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

(OP)
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

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

(OP)
I have tried
exit
quit
logout
to exit the router, but none of them can have the 2nd loop.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close