Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-25-2012, 09:38 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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
Reply With Quote
  #2  
Old 04-25-2012, 10:11 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,526
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?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-25-2012, 10:17 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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.
Reply With Quote
  #4  
Old 04-25-2012, 10:27 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,526
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-25-2012, 11:00 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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
Reply With Quote
  #6  
Old 04-25-2012, 11:08 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,526
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).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 04-26-2012, 10:41 AM
alfatron alfatron is offline
Registered User
 
Join Date: Apr 2012
Posts: 1
Hello.

I think that you missed the port number for telnet.

you should add "23" to vHosts(0) : vHosts(0) = "10.1.1.1 23", or to the connection command: crt.Session.Connect "/Telnet " & strHost & " 23".

good luck.
Reply With Quote
  #8  
Old 04-26-2012, 03:36 PM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,526
Thanks for posting alfatron!

As a note, as long as the server is listening on the standard port (Telnet port 23, SSH2 port 22), you do not need to specify the port except in the rare case where the Default Session (Default.ini file) may have been changed to use a non-standard port. The Default Session configuration is used for ad hoc connections.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:30 AM.