#1
|
|||
|
|||
VBScript does not wait for prompt and ends prematurely
Good day.
I wrote a script that's supposed to start different types of servers with a 3 minute pause between two different server types. The script, however, does not wait for the '$' prompt (line 83) before heading straight into the crt.Sleep command (line 85) and eventually finishes prematurely. In this case, the vmType is a 'icsf' and the script commences from line 43 (sleep) to line 80 (ElseIf vmType = "icsf"). Below is my script and it has some MsgBox comments: Code:
'#$language = "VBScript" '#$interface = "1.0" ' File: vCSCF-NovaStopStart-ALL.vbs 'Created 02/05/2019 - BH crt.Screen.Synchronous = True 'Create arrays for VMs Sub Main() Dim vNF vNF = crt.Dialog.Prompt("Enter the vNF name, eg: 'dpa2aicsf5001', 'dpa2bcscf5002', 'ksc1bcscf9001', etc.:") If vNF = "" Then Exit Sub 'Check if user is sourced Dim region region = (vNF) region = Left(region, Len(region) - 8 ) ' MsgBox(region) crt.Screen.Send "env | grep 'OS_REGION_NAME='" & region & vbCr If Not crt.Screen.WaitForString("OS_REGION_NAME=" & region, 2) Then MsgBox "You must be sourced to " & region & " before running this script!" Exit Sub End If 'Identify VM type (cscf or icsf) Dim vmType vmType = (vNF) vmType = Left(vmType, Len(vmType) - 4 ) vmType = Right(vmType, Len(vmType) - 5 ) 'Declare - nova stop or start Dim doWhat doWhat = crt.Dialog.Prompt("Enter 'stop' or 'start' :") If doWhat = "" Then Exit Sub MsgBox "Doing " & doWhat & " on " & vNF & " which is a " & vmType & " vm type." crt.Sleep 50 'Start nova commands If vmType = "cscf" Then If doWhat = "start" Then crt.Screen.Send"nova list | grep " & vNF & "vm00[1-3] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm00[6-7] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm00[4-5] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm10[1-8] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm00[8-9] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Sleep"180000" crt.Screen.Send"nova list | grep -E " & vNF & "'vm2[0-4][0-9]|" & vNF & "vm25[0-1]' | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" ElseIf doWhat = "stop" Then crt.Screen.Send"nova list | grep -E " & vNF & "'vm2[0-4][0-9]|" & vNF & "vm25[0-1]' | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm00[8-9] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm10[1-8] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm00[4-5] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm00[6-7] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm00[1-3] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "$" End If ElseIf vmType = "icsf" Then If doWhat = "start" Then crt.Screen.Send"nova list | grep " & vNF & "vm10[5-8] | cut '-d|' -f 3 | grep -v Running | xargs nova start" & vbCr crt.Screen.WaitForString "$" MsgBox"Why does it not wait for the '$' prompt on line 83 above before the 'sleep 180000 on line 85?" crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm23[1-4] | cut '-d|' -f 3 | grep -v Running | xargs nova start" & vbCr crt.Screen.WaitForString "$" ElseIf doWhat = "stop" Then crt.Screen.Send"nova list | grep " & vNF & "vm23[1-4] | cut '-d|' -f 3 | grep -v Shutdown | xargs nova stop" & vbCr crt.Screen.WaitForString "$" crt.Screen.Send"nova list | grep " & vNF & "vm10[5-8] | cut '-d|' -f 3 | grep -v Shutdown | xargs nova stop" & vbCr crt.Screen.WaitForString "$" End If End If 'Next MsgBox " *** End nova " & doWhat & " script. *** " MsgBox " Why did the script end prematurely??? It's still working on line 86!" End Sub Regards, Bjoern Last edited by BjoernH; 02-07-2019 at 10:47 AM. |
#2
|
|||
|
|||
Hi BjoernH,
It is unlikely that the WaitForString is simply not waiting, or being skipped, it is likely finding the "$" elsewhere in the output. Is it possible that the output of the preceding command contains a "$" somewhere in the output?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Quote:
Code:
'Declare - nova stop or start Dim doWhat doWhat = crt.Dialog.Prompt("Enter 'stop' or 'start' :") If doWhat = "" Then Exit Sub MsgBox "Doing " & doWhat & " on " & vNF & " which is a " & vmType & " vm type." crt.Screen.Send "echo Start time: `date '+%H:%M:%S'`" & vbCr crt.Screen.WaitForString "]$ " crt.Sleep 50 'Start nova commands If vmType = "cscf" Then If doWhat = "start" Then crt.Screen.Send"nova list | grep " & vNF & "vm00[1-3] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm00[6-7] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm00[4-5] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm10[1-8] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm00[8-9] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Sleep"180000" crt.Screen.Send"nova list | grep -E " & vNF & "'vm2[0-4][0-9]|" & vNF & "vm25[0-1]' | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " ElseIf doWhat = "stop" Then crt.Screen.Send"nova list | grep -E " & vNF & "'vm2[0-4][0-9]|" & vNF & "vm25[0-1]' | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm00[8-9] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm10[1-8] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm00[4-5] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm00[6-7] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm00[1-3] | cut '-d|' -f 3" & vbCr crt.Screen.WaitForString "]$ " End If ElseIf vmType = "icsf" Then If doWhat = "start" Then crt.Screen.Send"nova list | grep " & vNF & "vm10[5-8] | grep -v Running | cut '-d|' -f 3 | xargs nova start" & vbCr crt.Screen.WaitForString "]$ " MsgBox"Sleeping for 3 minutes." crt.Sleep"180000" crt.Screen.Send"nova list | grep " & vNF & "vm23[1-4] | grep -v Running | cut '-d|' -f 3 | xargs nova start" & vbCr crt.Screen.WaitForString "]$ " ElseIf doWhat = "stop" Then crt.Screen.Send"nova list | grep " & vNF & "vm23[1-4] | grep -v Shutdown | cut '-d|' -f 3 | xargs nova stop" & vbCr crt.Screen.WaitForString "]$ " crt.Screen.Send"nova list | grep " & vNF & "vm10[5-8] | grep -v Shutdown | cut '-d|' -f 3 | xargs nova stop" & vbCr crt.Screen.WaitForString "]$ " End If End If crt.Screen.Send "echo End time: `date '+%H:%M:%S'`" & vbCr crt.Screen.WaitForString "]$ " MsgBox " *** End nova " & doWhat & " script. *** " End Sub So what happens is the following, once it displays the start time, it jumps to the "Sleeping for 3 minutes" MsgBox. It sits there for 3 minutes and then it outputs the first command with the acceptance plus the next 'nova start' command. It's suppose to wait for 3 minutes between the two 'nova start' commands. I recorded the session, so if you want, I can email you the video and the script. Regards, Bjoern |
#4
|
|||
|
|||
Hi BjoernH,
I think a timestamped log file of the script running will likely be the biggest help. I've included a link below to a video that helps demonstrate configuring SecureCRT to create a log file with time stamps. SecureCRT Log File Name Substitution ParametersDO NOT POST YOUR LOG FILE IN THE FORUMS After creating a log file that demonstrates the issue please send it via email to Support@VanDyke.com with "Attn: Eric Forum Post 13393" in the subject line. Please be sure to attach the file rather than pasting the contents directly into the email.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|