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 offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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 offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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 offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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-25-2012, 11:14 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
Hello Brenda. Yes I have reuse disconnected tabs enabled. I am using version
6.1.1. Thanks.
Reply With Quote
  #8  
Old 04-25-2012, 11:20 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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:
    .
    .
    .
    crt.Screen.Send "logout" & vbCr

    ' Wait for the 'logout' command we just issued to disconnect us.
    ' Otherwise, when the script loops up to the top of the For..Next
    ' crt.Session.Connect() will likely fail since the script
    ' executes asynchronously from (and much faster than) the
    ' network activity associated with a disconnect...
    Do
        crt.Sleep(25)
    Loop While crt.Session.Connected

Next
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 04-25-2012, 11:40 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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
Reply With Quote
  #10  
Old 04-25-2012, 12:22 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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"
#$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

    If crt.Session.Connected Then
        Do 
            crt.Session.Disconnect
            crt.Sleep(25)
        Loop While crt.Session.Connected
    End If

    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
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 04-25-2012, 12:42 PM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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.
Reply With Quote
  #12  
Old 04-25-2012, 03:06 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
Hi rainman,

You lost me.

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)?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #13  
Old 04-25-2012, 03:22 PM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
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 ?
Reply With Quote
  #14  
Old 04-25-2012, 03:37 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,492
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.
__________________
Thanks,
--Brenda

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

Last edited by bgagnon; 04-25-2012 at 03:42 PM.
Reply With Quote
  #15  
Old 04-25-2012, 03:41 PM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
Hi Brenda. I will check the upgrade path. Which version do you think I need ?
Thanks.
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:57 PM.