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 04-22-2009, 10:08 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Run command in multiple tabs/sessions 'Error: Connection failed'

Hi,

I currently have the following script :

Code:
# $language = "VBScript"
# $interface = "1.0"

crt.Screen.Synchronous = True
crt.Session.Connect "/s dell/20.11-1"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.11-1.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr
crt.Session.DisConnect

crt.Screen.Synchronous = True
crt.Session.Connect "/s dell/20.11-2"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.11-2.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr
crt.Session.DisConnect

crt.Screen.Synchronous = True
crt.Session.Connect "/s dell/20.12-1"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.12-1.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr
crt.Session.DisConnect
I want to run it in multiple tabs (so I can see the output)
I tried the following script :

Code:
# $language = "VBScript"
# $interface = "1.0"

crt.Screen.Synchronous = True
crt.Session.ConnectInTab "/s dell/20.11-1"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.11-1.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr

crt.Screen.Synchronous = True
crt.Session.ConnectInTab "/s dell/20.11-2"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.11-2.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr

crt.Screen.Synchronous = True
crt.Session.ConnectInTab "/s dell/20.12-1"
crt.Screen.WaitForString "#"
crt.Screen.Send  "copy running-config tftp://192.168.5.5/20.12-1.txt" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & vbCr
First session (dell/20.11-1) connects and runs ok, but when it opens a new tab it gives the error :

Code:
CRT Scripting Runtime error



Error: Connection failed



File: T:\dell-script.vbs

Line: 12
But the session is connected when the script is stopped (about 1 sec after the error popup)

I already tried to add crt.sleep 2000 but it looks like this doesn't do anything
I added it between the following lines :

Code:
crt.Session.ConnectInTab "/s dell/20.11-2"
crt.sleep 2000
crt.Screen.WaitForString "#"
same error (without any waiting)

Any ideas ?

(and is it possible to connect and run at the same time ?)

Thnx,

Stephan
Reply With Quote
  #2  
Old 04-22-2009, 10:24 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
ddx,

Which exact version of SecureCRT are you running (Help / About Securecrt...)?

Also, when you ask, "is it possible to connect and run at the same time?", are you asking if it's possible to run these commands in each of the tabs in parallel within the same SecureCRT script, or are you asking something else?

Can you provide clarification?

Thanks.
--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
  #3  
Old 04-22-2009, 10:57 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Jake,

>Which exact version of SecureCRT are you running (Help / About >Securecrt...)?

version 6.1.4 (build 489)

>Also, when you ask, "is it possible to connect and run at the same time?",
>are you asking if it's possible to run these commands in each of the tabs in >parallel within the same SecureCRT script, or are you asking something else?

Correct I want to run the command in the tabs in parallel.
(i'll connect to about 20 sessions)
Reply With Quote
  #4  
Old 04-23-2009, 01:38 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Although it isn't possible to do true real-time parallel operations in multiple tabs from a single instance of a script, there are two options available to you if you want to achieve parallel (or near-parallel) operations in multiple tabs.
  1. Use 2 scripts in combination, a "Launcher" script, and a "Tab-Specific" script. The Launcher script takes care of launching instances of SecureCRT with special command line arguments that allow for running a separate ("Tab-Specific") script in each tab. One example of this 2-script combination is found in another forum thread.

  2. You can get close to parallel action within multiple tabs using some crazy scripting techniques. Here's some snippets of code from an example tftp backup script that we've been working on for an upcoming chapter in our scripting manual currently in development.
    Code:
    ' Define this as the address of the tftp server to which the Cisco configuration
    ' will be copied for each device.
    g_strTftpServerAddress = "192.168.0.1"
    
    ' The g_strConfigFilenameTemplate variable will be used to allow for dynamic
    ' config file naming based on the current session and the remote IP address
    ' of each of the routers to which we will be connecting.  This example shows
    ' one way of using "__SESSION_NAME__" as a to-be-substituted place-hoder for
    ' the session name (which will dynamically change as we iterate through each
    ' session, which is why using a templated substitution like "__SESSION_NAME__"
    ' might be a good idea.  Another example provided is "__REMOTE_IP_ADDRESS__".
    ' You can extend support for other substitution strings by adding appropriate
    ' code in the SendToAllTabs() function below.  You might also consider
    ' enhancing the WaitForInAllTabs() function to also allow for substitutions
    ' that are specific to each session in turn.
    g_strConfigFilenameTemplate = "__SESSION_NAME__--__REMOTE_IP_ADDRESS__.txt"
    
    ' Create an Array in which all of the sessions will be listed
    ' We'll use this Array to determine which hosts we'll connect to.
    g_vSessionsList = Array(_
        "dell/Device#1", _
        "dell/Device#2", _
        "dell/Device#3", _
        "dell/Device#4"  _ ) 
    
    ' Set up a dynamic array in which we will store references
    ' to tab objects for each tab to which we will connect.
    Dim g_vTabs()
    ReDim g_vTabs(0)
    
    g_strPrompt = "#"
    
    Sub Main()
    
        ' Attempt to connect to each session listed in the g_vSessionsList array. 
        nTabCount = 0
        for each strSession in g_vSessionsList
    
            ' Turn off normal Error Handling so that we can process any connection
            ' errors without halting script execution.
            On Error Resume Next
            Set objNewTab = crt.Session.ConnectInTab("/S " & strSession)
            nError = Err.Number
            strError = Err.Description
        ' Let's resume normal error handling now that our ConnectionInTab()
            ' call has returned
            On Error Goto 0
    
            ' Now, let's check to see if we were able to successfully connect.
            if nError = 0 then
    
                ' We did successfully connect...
                ' Resize the array to accomodate the new tab reference, if needed.
                if nTabCount > 0 then ReDim Preserve g_vTabs(nTabCount)
    
                ' Now, add the tab's reference object to our array of tab
                ' references.
                Set g_vTabs(nTabCount) = objNewTab
    
                ' Now is just as good a time as any to set the Screen's Synchronous
                ' property = True...
                objNewTab.Screen.Synchronous = True
                objNewTab.Activate
                
                nTabCount = nTabCount + 1
            else
    
                ' Let's display a warning and prompt to see if the user wants
                ' to continue running the script.
                if MsgBox("Unable to connect to session """ & strSession & """." & _
                          vbcrlf & vbcrlf & _
                          "Do you wish to continue with the script?", _
                          vbyesno) <> vbyes then exit sub
            end if
        next
    
        ' Now that we have an array of successfully-connected tabs, let's issue
        ' the commands we need to do in each of the tabs.
        ' First, we need to make sure that we're in a state where the remote is
        ' ready to receive commands. So, we'll first send a CR and then wait for
        ' our expected command prompt to appear; then we'll have a pretty good idea
        ' that the remote is connected and ready to receive commands.
        SendToAllTabs vbcr
        WaitForInAllTabs g_strPrompt
    
        ' Now, send the 'copy running-config...' command to each tab
        SendToAllTabs "copy running-config tftp://" & g_strTftpServerAddress & "/" & g_strConfigFilenameTemplate & vbcr
        WaitForInAllTabs g_strPrompt
    
        ' Now that the config has been copied, we'll disconnect from the device.
        ' We could use tab.disconnect, but we'll try to perform a "clean" disconnect
        ' so that we don't chance leaving the remote device in an unknown state.
        SendToAllTabs "exit"
        
        ' Before completing the "exit" command with a CR character, we'll wait for
        ' our "exit" command to be echo'ed to the SecureCRT screen; this will allow
        ' us to visually see the results of the command within the terminal window
        ' (otherwise, the "exit" command might cause a disconnect to occur before
        ' SecureCRT has time to display all of the received data to the screen.
        WaitForInAllTabs "exit"
    
        ' Now, actually send the CR character to each tab to complete the "exit"
        ' command.
        SendToAllTabs vbcr
    
    End Sub
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function WaitForInAllTabs(strWaitForString)
        for each objTab in g_vTabs
            objTab.Activate
            objTab.Screen.WaitForString strWaitForString        
        next
    End Function
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function SendToAllTabs(strSendString)
        for each objTab in g_vTabs
            strTextToSend = strSendString
    
    
            ' Look for any special substitutions that need to be made.
            if InStr(strTextToSend, "__SESSION_NAME__") > 0 then
                strSessionName = objTab.Session.Path
    
                ' Convert all path-separators to valid chars for filenames
                strSessionName = Replace(strSessionName, "/", "+")
                strSessionName = Replace(strSessionName, "\", "+")
    
    
                ' Now, replace our substitution string with the actual text of
                ' the "sanitized" session name...
                strTextToSend = Replace(strTextToSend, _
                                        "__SESSION_NAME__", _
                                        strSessionName)
            end if
            if Instr(strTextToSend, "__REMOTE_IP_ADDRESS__") > 0 then
                strTextToSend = Replace(strTextToSend, _
                                        "__REMOTE_IP_ADDRESS__", _
                                        objTab.Session.RemoteAddress)
            end if
            
            objTab.Activate
            objTab.Screen.Send strTextToSend
        next
    End Function
Does this information help?

--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
  #5  
Old 04-23-2009, 03:50 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Jake,

Thnx for the example script, looks like this works ok.
1 issue with this script :

Only Tab1 shows correct output

tab1:
Code:
User Name:

User Name:admin
Password:********

20.11-1# $y running-config tftp://192.168.5.5/dell+20.11-1--213.19.134.71.txt
it23-Apr-2009 10:46:21 %COPY-I-FILECPY: Files Copy - source URL running-config destination URL tftp://192.168.5.5/dell+20.11-1--213.19.134.71.txt
23-Apr-2009 10:46:23 %COPY-W-TRAP: The copy operation was completed successfully
!
2076 bytes copied in 00:00:02 [hh:mm:ss]

20.11-1#
tab2 : (with blinking cursor after the #)
Code:
User Name:

User Name:admin
Password:********

20.11-2# copy running-config tftp://192.168.5.5/dell+20.11-2--213.19.134.72.t
The config files are backuped, but I don't see the correct output in tab2 (and 3 etc)
I'm also unable to give input in these tab2+
Reply With Quote
  #6  
Old 04-23-2009, 10:54 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
I'm running the script in SecureCRT 6.2, and I don't see exactly what you're describing.

However, what you are describing can be attributed to the fact that SecureCRT's script thread runs independent of the main SecureCRT process's thread, and often times, at the tail end of a script, the script's ability to "see" data via WaitForString() can occur before SecureCRT's main thread can actually paint the text to the screen.

If automation is your goal, then needing to see data on the screen won't likely be that much of an issue. However, if you truly need to see the results on the screen, you might be able to introduce some crt.Sleep statements within the for..next loops in the WaitForInAllTabs() and SendToAllTabs(), respectively. Another alternative would be to introduce more WaitForString synchronization calls to give the SecureCRT screen a chance to catch up with your script. For example, if you add the following 3 lines to the bottom of your SendToAllTabs() function (right above your current 'next' statement), do you get better results in terms of what is displayed to the screen after the script is completed in each tab?

Code:
        On Error Resume Next
        objTab.Screen.WaitForString strTextToSend
        On Error Goto 0

The function should look like this when you're done adding the lines above.

Code:
Function SendToAllTabs(strSendString)
    for each objTab in g_vTabs
        strTextToSend = strSendString


        ' Look for any special substitutions that need to be made.
        if InStr(strTextToSend, "__SESSION_NAME__") > 0 then
            strSessionName = objTab.Session.Path

            ' Convert all path-separators to valid chars for filenames
            strSessionName = Replace(strSessionName, "/", "+")
            strSessionName = Replace(strSessionName, "\", "+")


            ' Now, replace our substitution string with the actual text of
            ' the "sanitized" session name...
            strTextToSend = Replace(strTextToSend, _
                                    "__SESSION_NAME__", _
                                    strSessionName)
        end if
        if Instr(strTextToSend, "__REMOTE_IP_ADDRESS__") > 0 then
            strTextToSend = Replace(strTextToSend, _
                                    "__REMOTE_IP_ADDRESS__", _
                                    objTab.Session.RemoteAddress)
        end if
        
        objTab.Activate
        objTab.Screen.Send strTextToSend

        On Error Resume Next
        objTab.Screen.WaitForString strTextToSend
        On Error Goto 0
    next
End Function
--Jake
The end result
__________________
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
  #7  
Old 04-23-2009, 11:59 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Jake,

With your change the copy command is never being sended to the other tabs.

Output on all other tabs :
Code:
User Name:
admin

Password:********

20.11-2#
No copyed config anymore, and still no input.

I also tried 6.2, but same issue

Last edited by ddx; 04-23-2009 at 12:07 PM.
Reply With Quote
  #8  
Old 04-23-2009, 03:18 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
I would guess that you're doing authentication (sending a password) in each one of your tabs, right?

That might explain why your seeing something different than I am (I had my authentication taken care of either by saving the password in the session, or using a simple expect/send logon sequence as allowed in Session Options).

The change I made will always cause an indefinite hang if you're sending a password to the remote within your script because the remote won't be echo'ing your password back, it will be echo'ing * characters instead. This causes my "quick" workaround to fail because one of the lines I added in order to try and synch things up a bit actually waits for what we sent to the remote to be echoed back to us. Fortunately for security, passwords and other known-sensitive data aren't usually echoed in plain-text back to the terminal client, but this prevents our synch method as-is from working as intended for those specific times in which we really need to send sensitive data to the remote.

There's two ways that I can think of to get around this issue...
  • You could create a SendHiddenTextToAllTabs() function that you use whenever you need to send text that isn't echo'ed by the remote (such is the case with passwords on most systems anyway.) This new function would be identical to your current SendToAllTabs() function, minus the 3 lines that I suggested you add earlier. The one drawback to this approach is that code is being duplicated.
  • Alternatively, you could modify your SendToAllTabs() function to take a second parameter, a boolean value (bWaitForEcho, for example) that indicates whether or not the function should wait for the remote to echo the data back to SecureCRT. This new version of the function would wrap the 3 lines I suggested you add earlier, in an if bWaitForEcho then... end if block. This option would require that you change all the places in which you currently call SendToAllTabs() to add a second parameter of True (all except for the place in which you're using it to send a password).

Probably the most ideal might be a combination of the two ideas above:
  1. Modify your current SendToAllTabs function declaration to have another parameter named bWait so that your function declaration looks like this:
    Function SendToAllTabs(strSendString, bWait)
  2. Modify the body of your SendToAllTabs function so that the 3 lines that wait for the text to be echoed from the remote are wrapped in an if..then statement. For example:
    Code:
            If bWait Then
                On Error Resume Next
                objTab.Screen.WaitForString strTextToSend
                On Error Goto 0
            End If
  3. Add a new function named SendNormalTextToAllTabs that looks like this:
    Code:
    Function SendNormalTextToAllTabs(strTextToSend)
        SendToAllTabs strTextToSend, True
    End Function
  4. Add a new function named SendHiddenTextToAllTabs that looks like this:
    Code:
    Function SendHiddenTextToAllTabs(strTextToSend)
        SendToAllTabs strTextToSend, False
    End Function
  5. Change all the places where you send commands and other normal text to the remote to use the SendPlainTextToAllTabs function instead of SendToAllTabs.
  6. Change all the places where you send passwords (probably just one line in your script, if I'm guessing correctly) to use the SendHiddenTextToAllTabs function instead of SendToAllTabs.
Does this help?

--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
  #9  
Old 04-27-2009, 03:54 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Quote:
Originally Posted by jdev
I would guess that you're doing authentication (sending a password) in each one of your tabs, right?

That might explain why your seeing something different than I am (I had my authentication taken care of either by saving the password in the session, or using a simple expect/send logon sequence as allowed in Session Options).
Jake,

I'm not sending the password from the script.
It's specified in each session (in Connection/Logon Actions).
Reply With Quote
  #10  
Old 04-27-2009, 12:10 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
ddx,

Which connection protocol are you using (telnet, SSH1, SSH2, etc)?

When it's clear that nothing is happening, is the "Cancel" menu item available within your main "Script" menu (on the first tab)?

If it is, what code line is indicated when you choose "Cancel" from the Script menu?

And, can you post your current version of the script so that we can synch up the line number indicated in the cancel message with the actual line of code (and related context) within your script?

--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
  #11  
Old 04-28-2009, 07:58 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Hi Jake,

I'm using ssh2 for the dell switches.

When I cancel the script, the line number is 151.

Current script :

Code:
' Define this as the address of the tftp server to which the Cisco configuration
' will be copied for each device.
g_strTftpServerAddress = "192.168.5.5"

' The g_strConfigFilenameTemplate variable will be used to allow for dynamic
' config file naming based on the current session and the remote IP address
' of each of the routers to which we will be connecting.  This example shows
' one way of using "__SESSION_NAME__" as a to-be-substituted place-hoder for
' the session name (which will dynamically change as we iterate through each
' session, which is why using a templated substitution like "__SESSION_NAME__"
' might be a good idea.  Another example provided is "__REMOTE_IP_ADDRESS__".
' You can extend support for other substitution strings by adding appropriate
' code in the SendToAllTabs() function below.  You might also consider
' enhancing the WaitForInAllTabs() function to also allow for substitutions
' that are specific to each session in turn.
g_strConfigFilenameTemplate = "__SESSION_NAME__--__REMOTE_IP_ADDRESS__.txt"

' Create an Array in which all of the sessions will be listed
' We'll use this Array to determine which hosts we'll connect to.
'g_vSessionsList = Array(_
'    "dell/Device#1", _
'    "dell/Device#2", _
'    "dell/Device#3", _
'    "dell/Device#4"  _ ) 
g_vSessionsList = Array ("dell/20.11-1","dell/20.11-2","dell/20.12-1","dell/20.12-2","dell/20.13-1","dell/20.13-2")




' Set up a dynamic array in which we will store references
' to tab objects for each tab to which we will connect.
Dim g_vTabs()
ReDim g_vTabs(0)

g_strPrompt = "#"

Sub Main()

    ' Attempt to connect to each session listed in the g_vSessionsList array. 
    nTabCount = 0
    for each strSession in g_vSessionsList

        ' Turn off normal Error Handling so that we can process any connection
        ' errors without halting script execution.
        On Error Resume Next
        Set objNewTab = crt.Session.ConnectInTab("/S " & strSession)
        nError = Err.Number
        strError = Err.Description
    ' Let's resume normal error handling now that our ConnectionInTab()
        ' call has returned
        On Error Goto 0

        ' Now, let's check to see if we were able to successfully connect.
        if nError = 0 then

            ' We did successfully connect...
            ' Resize the array to accomodate the new tab reference, if needed.
            if nTabCount > 0 then ReDim Preserve g_vTabs(nTabCount)

            ' Now, add the tab's reference object to our array of tab
            ' references.
            Set g_vTabs(nTabCount) = objNewTab

            ' Now is just as good a time as any to set the Screen's Synchronous
            ' property = True...
            objNewTab.Screen.Synchronous = True
            objNewTab.Activate
            
            nTabCount = nTabCount + 1
        else

            ' Let's display a warning and prompt to see if the user wants
            ' to continue running the script.
            if MsgBox("Unable to connect to session """ & strSession & """." & _
                      vbcrlf & vbcrlf & _
                      "Do you wish to continue with the script?", _
                      vbyesno) <> vbyes then exit sub
        end if
    next

    ' Now that we have an array of successfully-connected tabs, let's issue
    ' the commands we need to do in each of the tabs.
    ' First, we need to make sure that we're in a state where the remote is
    ' ready to receive commands. So, we'll first send a CR and then wait for
    ' our expected command prompt to appear; then we'll have a pretty good idea
    ' that the remote is connected and ready to receive commands.
    SendToAllTabs vbcr
    WaitForInAllTabs g_strPrompt

    ' Now, send the 'copy running-config...' command to each tab
    SendToAllTabs "copy running-config tftp://" & g_strTftpServerAddress & "/" & g_strConfigFilenameTemplate & vbcr
    WaitForInAllTabs g_strPrompt

    ' Now that the config has been copied, we'll disconnect from the device.
    ' We could use tab.disconnect, but we'll try to perform a "clean" disconnect
    ' so that we don't chance leaving the remote device in an unknown state.
    SendToAllTabs "exit"
    
    ' Before completing the "exit" command with a CR character, we'll wait for
    ' our "exit" command to be echo'ed to the SecureCRT screen; this will allow
    ' us to visually see the results of the command within the terminal window
    ' (otherwise, the "exit" command might cause a disconnect to occur before
    ' SecureCRT has time to display all of the received data to the screen.
    WaitForInAllTabs "exit"

    ' Now, actually send the CR character to each tab to complete the "exit"
    ' command.
    SendToAllTabs vbcr

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function WaitForInAllTabs(strWaitForString)
    for each objTab in g_vTabs
        objTab.Activate
        objTab.Screen.WaitForString strWaitForString        
    next
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function SendToAllTabs(strSendString)
    for each objTab in g_vTabs
        strTextToSend = strSendString


        ' Look for any special substitutions that need to be made.
        if InStr(strTextToSend, "__SESSION_NAME__") > 0 then
            strSessionName = objTab.Session.Path

            ' Convert all path-separators to valid chars for filenames
            strSessionName = Replace(strSessionName, "/", "+")
            strSessionName = Replace(strSessionName, "\", "+")


            ' Now, replace our substitution string with the actual text of
            ' the "sanitized" session name...
            strTextToSend = Replace(strTextToSend, _
                                    "__SESSION_NAME__", _
                                    strSessionName)
        end if
        if Instr(strTextToSend, "__REMOTE_IP_ADDRESS__") > 0 then
            strTextToSend = Replace(strTextToSend, _
                                    "__REMOTE_IP_ADDRESS__", _
                                    objTab.Session.RemoteAddress)
        end if
        
        objTab.Activate
        objTab.Screen.Send strTextToSend

        On Error Resume Next
        objTab.Screen.WaitForString strTextToSend
        On Error Goto 0
    next
End Function
Reply With Quote
  #12  
Old 04-28-2009, 11:02 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Hi ddx,

The script is idle, waiting for a string.
Code:
objTab.Screen.WaitForString strTextToSend
There may be things happening with your system that we're not easily able to know about or duplicate, but we think there could be a timing issue. What happens if you comment out SendToAllTabs vbcr on line 87 as shown below?
Code:
    ' Now that we have an array of successfully-connected tabs, let's issue
    ' the commands we need to do in each of the tabs.
    ' First, we need to make sure that we're in a state where the remote is
    ' ready to receive commands. So, we'll first send a CR and then wait for
    ' our expected command prompt to appear; then we'll have a pretty good idea
    ' that the remote is connected and ready to receive commands.
    'SendToAllTabs vbcr  'Commented this line out
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]

Last edited by miked; 04-28-2009 at 11:48 AM.
Reply With Quote
  #13  
Old 05-11-2009, 07:07 AM
ddx ddx is offline
Registered User
 
Join Date: Apr 2009
Posts: 25
Michael,

not helping same problem.
(and cancelling the script gives again line number 151)

Stephan
Reply With Quote
  #14  
Old 05-11-2009, 11:17 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,039
Hi Stephan,

Sorry to hear that didn't help. I'd like to get a little more information about what's happening. Can you send a log file and the current script to support@vandyke.com with a subject of "forum thread 3571 attn Mike"?

To enable logging open Session Options / Terminal / Log File and set the Log file name. Also, enable Start log upon connect.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #15  
Old 05-18-2009, 09:21 AM
burnt burnt is offline
Registered User
 
Join Date: May 2009
Posts: 2
Question /s vs /t

Quote:
Originally Posted by jdev
Although it isn't possible to do true real-time parallel operations in multiple tabs from a single instance of a script, there are two options available to you if you want to achieve parallel (or near-parallel) operations in multiple tabs.
  1. Use 2 scripts in combination, a "Launcher" script, and a "Tab-Specific" script. The Launcher script takes care of launching instances of SecureCRT with special command line arguments that allow for running a separate ("Tab-Specific") script in each tab. One example of this 2-script combination is found in another forum thread.

  2. You can get close to parallel action within multiple tabs using some crazy scripting techniques. Here's some snippets of code from an example tftp backup script that we've been working on for an upcoming chapter in our scripting manual currently in development.
    Code:
    ' Define this as the address of the tftp server to which the Cisco configuration
    ' will be copied for each device.
    g_strTftpServerAddress = "192.168.0.1"
    
    ' The g_strConfigFilenameTemplate variable will be used to allow for dynamic
    ' config file naming based on the current session and the remote IP address
    ' of each of the routers to which we will be connecting.  This example shows
    ' one way of using "__SESSION_NAME__" as a to-be-substituted place-hoder for
    ' the session name (which will dynamically change as we iterate through each
    ' session, which is why using a templated substitution like "__SESSION_NAME__"
    ' might be a good idea.  Another example provided is "__REMOTE_IP_ADDRESS__".
    ' You can extend support for other substitution strings by adding appropriate
    ' code in the SendToAllTabs() function below.  You might also consider
    ' enhancing the WaitForInAllTabs() function to also allow for substitutions
    ' that are specific to each session in turn.
    g_strConfigFilenameTemplate = "__SESSION_NAME__--__REMOTE_IP_ADDRESS__.txt"
    
    ' Create an Array in which all of the sessions will be listed
    ' We'll use this Array to determine which hosts we'll connect to.
    g_vSessionsList = Array(_
        "dell/Device#1", _
        "dell/Device#2", _
        "dell/Device#3", _
        "dell/Device#4"  _ ) 
    
    ' Set up a dynamic array in which we will store references
    ' to tab objects for each tab to which we will connect.
    Dim g_vTabs()
    ReDim g_vTabs(0)
    
    g_strPrompt = "#"
    
    Sub Main()
    
        ' Attempt to connect to each session listed in the g_vSessionsList array. 
        nTabCount = 0
        for each strSession in g_vSessionsList
    
            ' Turn off normal Error Handling so that we can process any connection
            ' errors without halting script execution.
            On Error Resume Next
            Set objNewTab = crt.Session.ConnectInTab("/S " & strSession)
            nError = Err.Number
            strError = Err.Description
        ' Let's resume normal error handling now that our ConnectionInTab()
            ' call has returned
            On Error Goto 0
    
            ' Now, let's check to see if we were able to successfully connect.
            if nError = 0 then
    
                ' We did successfully connect...
                ' Resize the array to accomodate the new tab reference, if needed.
                if nTabCount > 0 then ReDim Preserve g_vTabs(nTabCount)
    
                ' Now, add the tab's reference object to our array of tab
                ' references.
                Set g_vTabs(nTabCount) = objNewTab
    
                ' Now is just as good a time as any to set the Screen's Synchronous
                ' property = True...
                objNewTab.Screen.Synchronous = True
                objNewTab.Activate
                
                nTabCount = nTabCount + 1
            else
    
                ' Let's display a warning and prompt to see if the user wants
                ' to continue running the script.
                if MsgBox("Unable to connect to session """ & strSession & """." & _
                          vbcrlf & vbcrlf & _
                          "Do you wish to continue with the script?", _
                          vbyesno) <> vbyes then exit sub
            end if
        next
    
        ' Now that we have an array of successfully-connected tabs, let's issue
        ' the commands we need to do in each of the tabs.
        ' First, we need to make sure that we're in a state where the remote is
        ' ready to receive commands. So, we'll first send a CR and then wait for
        ' our expected command prompt to appear; then we'll have a pretty good idea
        ' that the remote is connected and ready to receive commands.
        SendToAllTabs vbcr
        WaitForInAllTabs g_strPrompt
    
        ' Now, send the 'copy running-config...' command to each tab
        SendToAllTabs "copy running-config tftp://" & g_strTftpServerAddress & "/" & g_strConfigFilenameTemplate & vbcr
        WaitForInAllTabs g_strPrompt
    
        ' Now that the config has been copied, we'll disconnect from the device.
        ' We could use tab.disconnect, but we'll try to perform a "clean" disconnect
        ' so that we don't chance leaving the remote device in an unknown state.
        SendToAllTabs "exit"
        
        ' Before completing the "exit" command with a CR character, we'll wait for
        ' our "exit" command to be echo'ed to the SecureCRT screen; this will allow
        ' us to visually see the results of the command within the terminal window
        ' (otherwise, the "exit" command might cause a disconnect to occur before
        ' SecureCRT has time to display all of the received data to the screen.
        WaitForInAllTabs "exit"
    
        ' Now, actually send the CR character to each tab to complete the "exit"
        ' command.
        SendToAllTabs vbcr
    
    End Sub
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function WaitForInAllTabs(strWaitForString)
        for each objTab in g_vTabs
            objTab.Activate
            objTab.Screen.WaitForString strWaitForString        
        next
    End Function
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function SendToAllTabs(strSendString)
        for each objTab in g_vTabs
            strTextToSend = strSendString
    
    
            ' Look for any special substitutions that need to be made.
            if InStr(strTextToSend, "__SESSION_NAME__") > 0 then
                strSessionName = objTab.Session.Path
    
                ' Convert all path-separators to valid chars for filenames
                strSessionName = Replace(strSessionName, "/", "+")
                strSessionName = Replace(strSessionName, "\", "+")
    
    
                ' Now, replace our substitution string with the actual text of
                ' the "sanitized" session name...
                strTextToSend = Replace(strTextToSend, _
                                        "__SESSION_NAME__", _
                                        strSessionName)
            end if
            if Instr(strTextToSend, "__REMOTE_IP_ADDRESS__") > 0 then
                strTextToSend = Replace(strTextToSend, _
                                        "__REMOTE_IP_ADDRESS__", _
                                        objTab.Session.RemoteAddress)
            end if
            
            objTab.Activate
            objTab.Screen.Send strTextToSend
        next
    End Function
Does this information help?

--Jake

I have used this thread as a reference for a script I have been working on. where I am generating a vb script from a perl parse of flat text data that I have. my issue now is that this is a session based script. is there a way I can convert this to a telnet session as with the /t command. I tried to simply replace the /S with /T but it just generated errors.

burnt
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 08:04 AM.