Telnet script not working
Hello. The following script is not working. Basically I want to telnet and login to the 3 switches one at at time then run a simple command and logout and then move onto the next switch, but the telnet command appears to be incorrect ? Can someone advise please ? Thanks.
#$interface = "1.0" crt.Screen.Synchronous = True Sub Main Dim vHosts(3) vHosts(0) = "10.1.1.1" vHosts(1) = "10.1.1.2" vHosts(2) = "10.1.1.3" For Each strHost In vHosts If strHost = "" Then Exit For crt.Session.Connect "/Telnet " & strHost crt.Screen.WaitForString "login: " crt.Screen.Send "username" & vbCr crt.Screen.WaitForString "Password: " crt.Screen.Send "pass1234!" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "Show ver" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "logout" & vbCr Next ' Turn off synchronous mode crt.Screen.Synchronous = false End Sub |
Hello rainman,
What do you mean by "the following script is not working"? Do you get an error message? (If so, what is the exact error message?) Does the script appear to hang? If so, if you choose Cancel from the Script menu, what is the error message? Or does the script just not do what is expected? |
Hello. I receive the error message: Session.connect: already connected. I then select OK. Nothing else happens. The script is not running. Your help is much appreciated. Thanks.
|
Hi rainman,
That matches my test results. You have not disconnected the current connection. If you want all three sessions to remain open, use ConnectInTab(). Otherwise, you would want to include a disconnect within the For loop. |
Hello Brenda, I have now added the session disconnect, but I still receive the same error messsage as previous. Line 18 of the script is were the error is given, this is where the crt.Session.Connect "/Telnet " & strHost line is. See updated script below. Can you please confirm line 18 is correct ? Thanks.
#$language = "VBScript" #$interface = "1.0" ' Turn on synchronous mode while performing Send/Wait sequences ' so no input is missed. crt.Screen.Synchronous = True Sub Main Dim vHosts(3) vHosts(0) = "10.1.1.1" vHosts(1) = "10.1.1.2" vHosts(2) = "10.1.1.3" For Each strHost In vHosts If strHost = "" Then Exit For crt.Session.Connect "/Telnet " & strHost crt.Screen.WaitForString "login: " crt.Screen.Send "username" & vbCr crt.Screen.WaitForString "Password: " crt.Screen.Send "pass1234!" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "Show ver" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "logout" & vbCr crt.Session.Disconnect Next ' Turn off synchronous mode crt.Screen.Synchronous = false End Sub |
Hi rainman,
Do you have Reuse disconnected tabs enabled in the Terminal / Tabs category of SecureCRT's Global Options? What version of SecureCRT are you using? (Help / About SecureCRT...) Line 18 does appear to be syntactically correct. My tests are slightly different (SSH2 instead of Telnet), but when I added the logout and disconnect lines, using Connect() works fine (with Reuse disconnected tabs enabled). |
Hello Brenda. Yes I have reuse disconnected tabs enabled. I am using version
6.1.1. Thanks. |
Hi rainman,
I have further information after consulting with a colleague. This is likely an issue of timing. In other words, the script executes too fast to give time for the session to disconnect. What are the results if you add the following after you send the logout command? Code:
. |
Hello Brenda, still the same error, see updated code below , Thanks
#$language = "VBScript" #$interface = "1.0" ' Turn on synchronous mode while performing Send/Wait sequences ' so no input is missed. crt.Screen.Synchronous = True Sub Main Dim vHosts(3) vHosts(0) = "10.1.1.1" vHosts(1) = "10.1.1.2" vHosts(2) = "10.1.1.3" For Each strHost In vHosts If strHost = "" Then Exit For crt.Session.Connect "/Telnet " & strHost crt.Screen.WaitForString "login: " crt.Screen.Send "username" & vbCr crt.Screen.WaitForString "Password: " crt.Screen.Send "pass1234!" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "Show ver" & vbCr crt.Screen.WaitForString "> " crt.Screen.Send "logout" & vbCr Do crt.Sleep(25) Loop While crt.Session.Connected Next crt.Session.Disconnect ' Turn off synchronous mode crt.Screen.Synchronous = false End Sub |
Hi rainman,
Since you are using an older version of SecureCRT, you might want to check your upgrade eligibility here. Are you already connected when you run the script? If so, you would need to include a check for this condition in your script. The below version of the script illustrates this: Code:
#$language = "VBScript" |
Hello Brenda, No I'm not connected before I run the script. After updating the script with your previous post, I now have a slightly different error message. It is - CRT Scritping Runtime error
Error:Connection failed Thanks. |
Hi rainman,
You lost me. :confused: Do you get the new error as soon as you run the script (ie: first host in the array)? If so, can you verify that you can connect manually to this IP address? If the error occurs on a different iteration (second or third host), could you verify connectivity to that particular host(s)? |
Hello Brenda, yes as soon as I run the script I get the error message.
I can telnet to all hosts fine , but if I try and run the script to connect I get the error message as detailed previously. Can you help thanks ? |
Hi rainman,
Did you check your upgrade eligibility? Are you able to use a more recent version of SecureCRT? I want to be sure my tests are in the same version of the product. Please post the current rendition of the script. I ran the last known version in SecureCRT 6.1.1 and it runs flawlessly except when I include an incorrect IP address, and then I get the same error you reported. |
Hi Brenda. I will check the upgrade path. Which version do you think I need ?
Thanks. |
All times are GMT -6. The time now is 10:17 AM. |