jamiecaesar / securecrt-tools

SecureCRT scripts, written in Python, for doing various tasks when connected to Cisco equipment.
Apache License 2.0
246 stars 78 forks source link

SaveRunning.py for Multiple Tabs #19

Closed Del35 closed 7 years ago

Del35 commented 8 years ago

Is there any trick to port the SaveRunning.py for Multiple Tabs? Could you provide the code?

Thanks in advance. BR.

jamiecaesar commented 8 years ago

The script should already be tab aware. You can run it in each tab at the same time without the different instances interfering with each other. Is there something different you are trying to do?

Del35 commented 8 years ago

Hi Jamie, I was trying to use the crt.GetTabCount to get the number of opened tabs, with the while loop apply the SaveRunning.py code to each tab in a sequence using the crt.GetTab.Activate(), in order to open multiple tabs and save the config for all opened tabs. Do you think it´s possible? Thanks!!

jamiecaesar commented 8 years ago

I apologize for the delay, as I've been covered up with work most of my waking hours this past week. Honestly, I don't know how easy it would be to make this happen, as I've never tried it. From a quick glance I took at the documentation a few days ago, I seems like you should be able to loop through the tab index and run the same commands in each one. When I get some free time, I'll try to look into this, but if you get it working before then, I'd love to see what you did.

methridge commented 8 years ago

Hey BR:

I'm assuming you looked at this example https://www.vandyke.com/support/securecrt/scripts/SendCommandToTabs.py.txt as a starting point.

Just a quick idea would be to take the SaveRunning script and rename the current Main() to SaveRunning(). Then use this as a potential for the Main() function:

def Main():
    # Activate each tab in order from left to right, and issue the command in
    # each "connected" tab...
    skippedTabs = ""
    for i in range(1, crt.GetTabCount()+1):
        tab = crt.GetTab(i)
        tab.Activate()
        # Skip tabs that aren't connected
        if tab.Session.Connected == True:
            # Call Save Running
            SaveRunning()
        else:
            if skippedTabs == "":
                skippedTabs = str(i)
            else:
                skippedTabs = skippedTabs + "," + str(i)

    # Now, activate the original tab on which the script was started
    initialTab.Activate()

    # Determine if there were any skipped tabs, and prepare a message for
    # displaying at the end.
    if skippedTabs != "":
        skippedTabs = "\n\n\The following tabs did not receive the command because\n\
they were not connected at the time:\n\t" + skippedTabs

    crt.Dialog.MessageBox("The following command was sent to all \
connected tabs:\n\t" + command + skippedTabs)

Main()

Not sure if it will work or not. I just did a quick hack of the example above.

methridge commented 8 years ago

So, I played around with this a bit. And because we use objTab = crt.GetScriptTab() in the StartSession function. All commands go back to the initial script tab even if we activate a new one. So, we'd have to change how we reference the tab for this to work.

Here's what I had working. SaveRunning-MultiTab.py.txt

jamiecaesar commented 7 years ago

Finally getting around to cleaning up the issues list. In the end, these scripts are all designed to run in the tab that was open when the script was called. While I'm sure it is possible to write a script that runs on all open tabs, that isn't the direction I'm planning on going with these scripts so I'm going to close this issue.