Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-10-2009, 11:02 AM
cwsonline cwsonline is offline
Registered User
 
Join Date: Mar 2009
Posts: 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.
Reply With Quote
  #2  
Old 03-10-2009, 12:38 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Quote:
Is there a way to either:
1. Run a script on all tabs.
2. Modify a script to run a script on each tab?
It is possible to either run a separate script in all tabs, or to run a single script that acts on all tabs.

Quote:
The problem is that all commands are run before moving to the next tab.
Something like a WaitForString could cause this behavior, but I'd need to see your script to know what's causing the script to wait at each tab.

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
Does this example help?

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]
Reply With Quote
  #3  
Old 05-01-2013, 05:59 PM
tty001 tty001 is offline
Registered User
 
Join Date: May 2013
Posts: 1
Thumbs up this is great

this is great... to take this little further - how to make it run simultaneously in all tabs... instead of one tab at a time?
Reply With Quote
  #4  
Old 05-02-2013, 12:51 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
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
If you need to run a tab simultaneously in multiple tabs, then you'll need an external script or batch file to kick things off.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply

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 06:14 AM.