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 08-23-2016, 02:23 PM
fredless fredless is offline
Registered User
 
Join Date: Mar 2016
Posts: 4
Connect to multiple hosts and execute a script on each - asynchronously

Scenario is this: have a script which reads a list of hosts into an array; then walks the array, connecting to each host (adhoc) & executing a configuration script.

My issue is that this operation occurs serially\synchronously and the script requires several minutes per host to complete. When our host array hit 50-200 hosts, the wait time for the whole process to execute is quite long obviously.

Is there way to programmatically spawn new tabs and have each tab execute a script independently? Obviously this is possible at some level, as you can do this when connecting to multiple saved sessions interactively. You can also use the /script standard argument to do this from the Win command line (but that isn't a scalable solution when you are talking about this many simultaneous connections, I've tried). But I haven't figured out a straightforward way to do this with adhoc sessions in script.

Working with v8.0.2
Reply With Quote
  #2  
Old 08-23-2016, 06:18 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 937
First, it's been my experience that SecureCRT's performance can handle 30-40 simultaneous connections open in Tabs within the same SecureCRT window before it becomes too bogged down, so I'd limit each "batch" to ~30 sessions at a time, to begin with.

Second, depending on how you want to accomplish what you're doing, you might want to move through blocks of 30 at a time and use the ability of the SecureCRT button bar to shift-click a button and have that action take place in parallel in all connected tabs in the same SecureCRT window. Here's an example script for your learning and benefit to demonstrate this approach in brevity:
Code:
' TabSafeScriptingExample(Shift-Click-ButtonBar).vbs
'
' Exemplifies tab-safe scripting so that the same script can
' run in parallel in each connected Tab in the self-same
' SecureCRT window by shift-clicking a button on the Button
' Bar that is set to run this script.

Set objTab = crt.GetScriptTab
objTab.Screen.Synchronous = True

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()
    nTabIndex = objTab.Index
    ' Get the text to the left of the cursor as the shell prompt
    strPrompt = objTab.Screen.Get(_
        objTab.Screen.CurrentRow, 1, _
        objTab.Screen.CurrentRow, objTab.Screen.CurrentColumn - 1)

    '======
    ' Send a command 'term len 0':
    strCmd = "term len 0"
    objTab.Screen.Send strCmd & vbcr
    ' Wait for the command to be echoe'd back:
    objTab.Screen.WaitForString strCmd & vbcr
    ' Wait for evidence that the command has completed (shell prompt appears):
    objTab.Screen.WaitForString strPrompt

    ' ======
    ' Send a command 'sh run':
    strCmd = "sh run"
    objTab.Screen.Send strCmd & vbcr
    ' Wait for the command to be echoe'd back:
    objTab.Screen.WaitForString strCmd & vbcr
    ' Wait for evidence that the command has completed (shell prompt appears):
    objTab.Screen.WaitForString strPrompt

    ' ======
    ' Send a command 'sh startup':
    strCmd = "sh startup"
    objTab.Screen.Send strCmd & vbcr
    ' Wait for the command to be echoe'd back:
    objTab.Screen.WaitForString strCmd & vbcr
    ' Wait for evidence that the command has completed (shell prompt appears):
    objTab.Screen.WaitForString strPrompt

    ' ---------------------------------------------------------------------
    ' Display time of completion (w/ms) in the status bar for this tab/session:
    crt.Session.SetStatusText "Tab #" & nTabIndex & " done: " & _
        GetCurTimeWithMSeconds
End Sub


' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetCurTimeWithMSeconds()
    ' Use WMI to get at the current time values
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For Each objItem In colItems
        strLocalDateTime = objItem.LocalDateTime
    Next
    ' strLocalDateTime has the following pattern:
    ' 20111013093717.418000-360   [ That is,  YYYYMMDDHHMMSS.MILLIS(zone) ]
    strYear = Left(strLocalDateTime, 4)
    strMonth = Mid(strLocalDateTime, 5, 2)
    strDay = Mid(strLocalDateTime, 7, 2)
    strHour = Mid(strLocalDateTime, 9, 2)
    strMinute = Mid(strLocalDateTime, 11, 2)
    strSecond = Mid(strLocalDateTime, 13, 2)
    ' skip the "." and start with offset char #16
    strMillis = Mid(strLocalDateTime, 16, 3)  ' 6 digits, but last 3 are always zero
    GetCurTimeWithMSeconds = strYear & strMonth & strDay & "_" & _
        strHour & strMinute & strSecond & "." & strMillis
End Function
Third, if you really want to go down the semi-parallel route through scripting w/o the use of the button bar shift-click method, you'd want to engineer your script to issue one command at a time in each of your tabs (in series) within your script. Instead of waiting for the entire series of commands to complete in one tab and then moving on to the next, you'd wait for the current command to complete in each and every tab, before moving on with the next command and so on. This way, only the slowest tab of all would hold up the process. This concept is demonstrated in the "RunCommandsInParallelTabs(Pseudo).vbs.txt" file attached to this existing forum post by bgagnon.

--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


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 01:56 AM.