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 09-16-2020, 10:06 AM
pjano1 pjano1 is offline
Registered User
 
Join Date: Mar 2020
Posts: 7
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
Reply With Quote
  #2  
Old 09-16-2020, 12:29 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,039
Quote:
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:
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
__________________
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
  #3  
Old 09-22-2020, 12:58 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,039
Quote:
Originally Posted by jdev View Post
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
__________________
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

Tags
linux , local shell , python


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 03:42 PM.