View Single Post
Old 09-16-2020, 11:29 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Originally Posted by pjano1 View Post
I'm trying to use the function crt.Session.ConnectInTab to open a Local Shell session that doesn't already exist in Linux. Ideally, I'd also like to be able to name it custom so I can then open more than one Local Shell session, all named differently. I didn't create Local Shell sessions already because I would like to add the functionality of creating new sessions when they don't exist into my infrastructure
/LOCAL is a sub-option that only applies to the /SSH1 or /SSH2 options; it's the way you configure local port forwarding. /LOCAL is not how you establish an ad hoc Local Shell protocol tab.

Currently there is no command line option for connecting a Local Shell protocol ad hoc tab. I've created a feature request for it, and we'll post here should something become available a la /LOCALSHELL, for example.

In the mean time, you can use a workaround in your script that will allow you to connect a local shell by activating the same event that allows the Alt+Shift+L keyboard shortcut or the File / Connect Local Shell functionality to work: MENU_CONNECT_LOCAL_SHELL

Here's an example that opens up 4 different Local Shell connections, each labeled LS1, LS2, LS3, and LS4 in sequence:
# $language = "Python"
# $interface = "1.0"

bTabCountExpectedToChange = True

if crt.Config.GetOption("Reuse Disconnected Tabs") and not crt.Session.Connected:
    bTabCountExpectedToChange = False  

cNewLocalShells = ["LS1", "LS2", "LS3", "LS4"]

for strTabName in cNewLocalShells:
    # Get the number of tabs *before* we try to connect a local shell...
    nTabs = crt.GetTabCount()
    # If we don't expect the tab count to change, just wait for the
    # current tab to be connected.
    if not bTabCountExpectedToChange:
        while not crt.Session.Connected:
        objNewTab = crt.GetScriptTab()
        # From here on, however, we'll expect the tab count to change
        # as new tabs are added.
        bTabCountExpectedToChange = True
        # If the tab count is expected to change (we're not reusing
        # the current active tab that is disconnected), then we need
        # to wait until the tab count changes so that we can get a
        # reference to the new tab and use that reference to rename
        # the tab as desired.
        while crt.GetTabCount() <> (nTabs + 1):
        objNewTab = crt.GetTab(crt.GetTabCount())

    # Now that we have a reference to the tab what was just connected
    # to a Local Shell, we can rename it to our desired value:
    objNewTab.Caption = strTabName
# The following block of code is useful for closing the "Script Tab"
# that gets left behind in the event that:
#   - You have SecureCRT configured to *not* reuse a disconnected
#     tab (by default, SecureCRT will not reuse disconnected tabs)
# and
#   - You don't already have any tabs open before running the script.
objScriptTab = crt.GetScriptTab()
if objScriptTab.Caption == "Script Tab":
    # Nothing below the line above will get executed because this
    # script was running in the tab that will have been closed by
    # the statement above. It's good these are only comments :)
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel:
Reply With Quote