|
#1
|
|||
|
|||
Make Secure CRT script wait till command finished
When I use VBS to run command on a device my script keeps running through commands until the end without waiting for previous device command to finish.
for example in the following script. The commands on the router take a few seconds to execute but the last command "msgbox("done") is executed immediately. Is there any way to make the script wait till the commands are executed. # $language = "VBScript" # $interface = "1.0" Sub Main crt.Screen.Synchronous = True crt.Session.Connect "/TELNET x.x.x.x 23" crt.Screen.WaitForString "sername:" crt.Screen.Send "xxx" & vbCr crt.Screen.WaitForString "assword:" crt.Screen.Send "sl@x" & vbCr crt.Screen.Send "show ip int br" & vbCr crt.Screen.Send "show cdp neighbors" &vbCr crt.Screen.Send "ping 8.8.8.8" & vbCr crt.Screen.Synchronous = False msgbox("Done") End Sub |
#2
|
||||
|
||||
Quote:
Scripting calls happen *very* quickly... so quickly in fact that the remote device to which you're connected might very well drop some/all command text you've sent after the first one because it's too busy processing the data from the first command to worry about input. Thinking about how you would do this manually, you wouldn't type a new command into the terminal window while the remote device is displaying output from a prior command you've issued. You'd wait for an indication from the device that it's ready for another command. Typically this indication is the device's shell prompt appears, giving you a visual indication the device is ready for a command. Do the same thing in your script code: Wait for the shell prompt as an indication that the remote device is ready for a(nother) command to run. In the other thread you posted recently, my response mentions a few ways to go about determining what your shell prompt is. Reliable automation code in SecureCRT will almost always exhibit a pattern of Send() followed by a corresponding WaitFor*() call or a ReadString() call (to capture output into a variable, not just wait for it). For example: Code:
strPrompt = "Router#" crt.Screen.Synchronous = True ' Send a command: crt.Screen.Send("command 1") ' Wait for the remote device to be ready for another command: crt.Screen.WaitForString(strPrompt) ' Send another command: crt.Screen.Send("command 2") ' Wait for the remote device to be ready for another command: crt.Screen.WaitForString(strPrompt) ' Send another command: crt.Screen.Send("command 3") ' Wait for the remote device to be ready for another command: crt.Screen.WaitForString(strPrompt) ' Send another command: crt.Screen.Send("command 4") ' Wait for the remote device to be ready for another command: crt.Screen.WaitForString(strPrompt) ' Send another command: crt.Screen.Send("command 5") ' Wait for the remote device to be ready for another command: crt.Screen.WaitForString(strPrompt) ' ... Also, look at the examples of code found in the Scripting "Sticky". There you might just find examples that help you in the project you're working on. --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
|
|||
|
|||
Have you tried adding:
crt.Screen.WaitForString "#" after each line that sends a command? Since these commands are on cisco gear, what you need to wait for is the # character, then each command will do its things and move on to the next line.. see below... Code:
# $language = "VBScript" # $interface = "1.0" Sub Main crt.Screen.Synchronous = True crt.Session.Connect "/TELNET x.x.x.x 23" crt.Screen.WaitForString "sername:" crt.Screen.Send "xxx" & vbCr crt.Screen.WaitForString "assword:" crt.Screen.Send "xxx" & vbCr crt.Screen.Send "show ip int br" & vbCr crt.Screen.WaitForString "#" crt.Screen.Send "show cdp neighbors" &vbCr crt.Screen.WaitForString "#" crt.Screen.Send "ping 8.8.8.8" & vbCr crt.Screen.WaitForString "#" crt.Screen.Synchronous = False msgbox("Done") End Sub Last edited by jdev; 12-13-2016 at 11:32 AM. |
![]() |
Tags |
command delay , vbs , wait |
Thread Tools | |
Display Modes | Rate This Thread |
|
|