#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
Quote:
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 Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#3
|
||||
|
||||
Quote:
If you're interested in trying it out, please send email to support@vandyke.com:
--Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
![]() |
Tags |
linux , local shell , python |
Thread Tools | |
Display Modes | Rate This Thread |
|
|