VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   ConnectInTab (https://forums.vandyke.com/showthread.php?t=6530)

WesR 12-06-2010 12:52 PM

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

jdev 12-06-2010 02:17 PM

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

WesR 12-06-2010 04:27 PM

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

jdev 12-06-2010 09:43 PM

Wes,

You are welcome. Glad it was helpful.

--Jake


All times are GMT -6. The time now is 04:41 PM.