VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Connect to Linux Local Shell through a script (https://forums.vandyke.com/showthread.php?t=14286)

pjano1 09-16-2020 09:06 AM

Connect to Linux Local Shell through a script
 
Hello,

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

I've tried the following (and similar) commands:

tab = crt.ConnectInTab("/LOCAL <IP> <hostname>")

I keep getting the error "/LOCAL requires [localip:]localport:hostname:hostport" and I've tried including these options but I don't think I'm doing it right

Any idea how to do this properly? Is this something I'm able to do in SecureCRT?

Thanks!
Paul

jdev 09-16-2020 11:29 AM

Quote:

Originally Posted by pjano1 (Post 54018)
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:
Code:

# $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()
    crt.Screen.SendSpecial("MENU_CONNECT_LOCAL_SHELL")
   
    # 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:
            crt.Sleep(25)
        objNewTab = crt.GetScriptTab()
       
        # From here on, however, we'll expect the tab count to change
        # as new tabs are added.
        bTabCountExpectedToChange = True
       
    else:
        # 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):
            crt.Sleep(25)
        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":
    objScriptTab.Activate()
    objScriptTab.Screen.SendSpecial("MENU_TAB_CLOSE")
    # 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

jdev 09-22-2020 11:58 AM

Quote:

Originally Posted by jdev (Post 54021)
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.

A /LOCALSHELL command line option has now been implemented and is available in a pre-release version of SecureCRT 9.0.

If you're interested in trying it out, please send email to support@vandyke.com:
  • Use the following subject: ATTN: Request for SecureCRT 9.0 prelease with /LOCALSHELL support (Forum thread 14286)
  • Send your email from the same email address you use to download SecureCRT installers from our web site (or include the email address of your download account in the body of your email message).
If you're reading this message after 9.0 Beta 1 (or newer 9.0 beta version) has already been released, download the beta to get access to try out the new /LOCALSHELL CLI/Connect() protocol specification functionality.

--Jake


All times are GMT -6. The time now is 11:25 PM.