View Single Post
  #1  
Old 02-07-2019, 11:44 AM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 41
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
Got a fix for me Eric?

Regards,
Bjoern

Last edited by BjoernH; 02-07-2019 at 11:47 AM.
Reply With Quote