|
#1
|
|||
|
|||
Run script on all tabs?
I often have dozens of tabs open that I need to run the same script on. Usually I just 'ctrl-tab alt-s 1' over and over again until I have started a the latest script on each of the tabs. Is there a way to either:
1. Run a script on all tabs. 2. Modify a script to run a script on each tab? I have made some modifications to a script that determines the number of tabs then runs the series of commands on each tab. The problem is that all commands are run before moving to the next tab. This is more automated but much much slower. Thank you for your help. |
#2
|
||||
|
||||
Quote:
Quote:
Here is an example script that sends a command to multiple tabs. Code:
# $language = "VBScript" # $interface = "1.0" ' Example script showing how to send commands to multiple tabs Option Explicit Sub Main() Dim tab, index, nTabCount nTabCount = crt.GetTabCount() for index = 1 to nTabCount set tab = crt.GetTab(index) tab.activate tab.screen.send "ping 192.168.0.131" & vbcr next End Sub If the example above doesn't help could you send your script to support@vandyke.com with a subject "Forum thread 3478 attn Mike"?
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#3
|
|||
|
|||
![]()
this is great... to take this little further - how to make it run simultaneously in all tabs... instead of one tab at a time?
|
#4
|
||||
|
||||
A single script cannot run simultaneously in all tabs.
However, each tab can run a separate script as long as the script doesn't try to manipulate other tabs. Using crt.Screen.Send is safe to use with a tab if the script is not trying to access or control more than the one script tab, as would be the case when each tab is running its own script. The best way to start a script in each tab depends on what you're trying to do. For example, the following script could be run as a logon script (Session Options / Connection / Logon Actions / Logon script) because it doesn't require any arguments to be passed to it. If you have a simple script that just needs to logon and start running, and doesn't need parameters, consider the following as a kind of base script. Code:
# $language = "VBScript" # $interface = "1.0" ' If target can be passed as argument to the script, ' you may want to uncomment the following line: ' target = crt.arguments(0) target = crt.Session.RemoteAddress Sub Main() strShellPrompt = GetShellPrompt() If strShellPrompt <> "" Then crt.screen.send "ping -c 5 " & target & vbcr End If End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetShellPrompt() ' Heuristically dermine the shell's prompt. Crt.Screen.Synchronous must ' already have been set to True. In general, Crt.Screen.Synchronous should ' be set to True immediately after a successful crt.Session.Connect(). In ' This script, SecureCRT should already be connected -- otherwise, a script ' error will occur. bSynchValueBefore = crt.Screen.Synchronous crt.Screen.Synchronous = True Do ' Simulate pressing "Enter" so the prompt appears again... crt.Screen.Send vbcr ' Attempt to detect the command prompt heuristically by waiting for the ' cursor to stop moving... (the timeout for WaitForCursor above might ' not be enough for slower- responding hosts, so you will need to adjust ' the timeout value above to meet your system's specific timing ' requirements). Do bCursorMoved = crt.Screen.WaitForCursor(1) Loop Until bCursorMoved = False ' Once the cursor has stopped moving for about a second, it's assumed ' it's safe to start interacting with the remote system. Get the shell ' prompt so that it's known what to look for when determining if the ' command is completed. Won't work if the prompt is dynamic (e.g., ' changes according to current working folder, etc.) nRow = crt.Screen.CurrentRow strPrompt = crt.screen.Get(nRow, _ 0, _ nRow, _ crt.Screen.CurrentColumn - 1) ' Loop until a line of non-whitespace text actually appears: strPrompt = Trim(strPrompt) If strPrompt <> "" Then Exit Do Loop GetShellPrompt = strPrompt crt.Screen.Synchronous = bSynchValueBefore End Function
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|