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 12-06-2010, 12:52 PM
WesR WesR is offline
Registered User
 
Join Date: Mar 2005
Location: USA
Posts: 149
ConnectInTab

I'm trying to write a simple script to prompt the user for an IP address and then telnet to that address and login. In the past I've used predefined sessions and then called a script. In this case I just want to be able to run the script from within SecureCRT and have it connect with a new tab.

The problem I'm having is it is giving me an error stating that the session is not connected when it gets to the the WaitforString command. Apparently the script is waiting on input on the original tab, not the newly created tab and I just can't seem to figure out how to get it to wait in the new tab.

Currently I have something like this:

Quote:
crt.session.ConnectInTab(" /telnet " & HostName)
crt.Screen.WaitforString "Login:"
It creates the new tab and connects, but I think I'm missing something to point to the new tab. Hope this makes sense.

Running ver 6.6.1

Wes
Reply With Quote
  #2  
Old 12-06-2010, 02:17 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,098
crt.Screen always refers to the script tab - the tab that was active when a script was launched.

In your case, you've launched the script with Tab #X activated, but in that script, you're trying to drive a new tab -- a tab for which your current code doesn't have any valid reference.

By default, the ConnectInTab() method will return a valid tab object if it successfully connects to the specified host. However, if the connection attempt fails, your script would come to a halt.

Fortunately, SecureCRT 6.6.1's ConnectInTab() sports a few additional parameters that will help you have more control over the connection process.

Here's the syntax for ConnectInTab():

Set objTab = object.ConnectInTab [arg [, True|False] [, True|False]]

The 3 parameters, from left->right are:
  • arg: connection string specifying protocol & hostname (and other info as desired)
  • bWaitForAuthToComplete: boolean value indicating whether you want the call to complete as soon as a TCP/IP connection is successfully established (True), or if you wish to only return from the call when authentication to the server has been completed (False, default).
  • bLetCallerHandleConnectionErrors: boolean value indicating whether you want SecureCRT to fail the call if the connection fails and bail out (False, default) or let the caller -- the script author -- handle any errors (True). If True, ConnectInTab will always return a valid Tab object which can be used to detect successful connection by looking at the Tab object's Session.Connected property.

So, to connect in a new tab, you'd call crt.Session.ConnectInTab as follows:
Set objTab = crt.Session.ConnectInTab("/Telnet " & strHost, False, True)

Once the call completes, you'd use "objTab" (instead of "crt") for all the tab-specific actions you need to perform within the newly-connected tab. For example:
Code:
If objTab.Session.Connected Then
    objTab.Screen.WaitForString "ogin:"
    objTab.Screen.Send strUser & vbcr
    '.
    '.
    '.
End If
Putting it all together for a "simple" script you can end up with something like the "ConnectInTabToSpecifiedHostname-HandlePasswordAuthInTerminalWindow.vbs.txt" example found in this other forum post.
Note that if you wanted to use such a script with ad hoc SSH connections, you would need to edit your default session so the following option is enabled(Global Options / General / Default Session ... Edit Default Settings... ... Connection / Logon Actions, Display logon prompts in terminal window)

Does this information help you?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 02-22-2018 at 11:37 AM.
Reply With Quote
  #3  
Old 12-06-2010, 04:27 PM
WesR WesR is offline
Registered User
 
Join Date: Mar 2005
Location: USA
Posts: 149
Thanks, this appears to be exactly what I was missing. And thanks for the thorough explanation.

I had played with the 'Set objtab =' syntax, but I was missing the 'use objtab instead of crt' part.

Wes
Reply With Quote
  #4  
Old 12-06-2010, 09:43 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,098
Wes,

You are welcome. Glad it was helpful.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
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 04:52 PM.