|
![]() |
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
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 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 Code:
CRT Scripting Runtime error Error: Connection failed File: T:\dell-script.vbs Line: 12 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 "#" Any ideas ? (and is it possible to connect and run at the same time ?) Thnx, Stephan |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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) |
#4
|
||||
|
||||
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.
--Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#5
|
|||
|
|||
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# 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 I'm also unable to give input in these tab2+ |
#6
|
||||
|
||||
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 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 |
#7
|
|||
|
|||
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# I also tried 6.2, but same issue Last edited by ddx; 04-23-2009 at 12:07 PM. |
#8
|
||||
|
||||
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...
Probably the most ideal might be a combination of the two ideas above:
--Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#9
|
|||
|
|||
Quote:
I'm not sending the password from the script. It's specified in each session (in Connection/Logon Actions). |
#10
|
||||
|
||||
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 |
#11
|
|||
|
|||
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 |
#12
|
||||
|
||||
Hi ddx,
The script is idle, waiting for a string. Code:
objTab.Screen.WaitForString strTextToSend 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. |
#13
|
|||
|
|||
Michael,
not helping same problem. (and cancelling the script gives again line number 151) Stephan |
#14
|
||||
|
||||
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] |
#15
|
|||
|
|||
![]() Quote:
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 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|