Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-16-2018, 04:26 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 26
Need help with Case/Do/Loop

Good day.

I've been trying to get this script to loop through a disk file on the local PC and issue a command (nova start) to start virtual machines listed in the file. I create the file in c:\temp\vmList.txt.

Contents of c:\temp\vmList (more or less):

Code:
nova start dpa2ascas5001vm011
nova start dpa2ascas5001vm012
echo INFRA
nova start dpa2ascas5001vm001
nova start dpa2ascas5001vm002
echo OAM
etc.
When it reaches a certain VM, it's supposed to pause and bring up a MsgBox instruction for the user when WaitForStrings recognizes the echo result (INFRA, STORAGE, OAM, etc.). The script doesn't stop at Case "12", instead simply stacks the commands before the previous one has finished.

My code:

Code:
Sub Main

Dim vnfName

vnfName = crt.Dialog.Prompt("Enter the vnf name, ie: dpa2bscas5001, san4ascas9001:")
	If vnfName = ""  Then Exit Sub

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForWriting = 2
Const ForAppending = 8

Set objStream = objFSO.OpenTextFile( _
 "C:\temp\vmList.txt", _
 ForAppending, _
 True)
 
objStream.WriteLine "nova start " & vnfName & "vm011" & vbcrlf & _
					"nova start " & vnfName & "vm002" & vbcrlf & _
					"echo INFRA" & vbcrlf & _
					"nova start " & vnfName & "vm004" & vbcrlf & _
					"echo STORAGE" & vbcrlf & _
					"nova start " & vnfName & "vm001" & vbcrlf & _
					"echo OAM" & vbcrlf & _
					"nova start " & vnfName & "vm014" & vbcrlf & _
					"nova start " & vnfName & "vm015" & vbcrlf & _
					"echo REPORTING" & vbcrlf & _
					"nova start " & vnfName & "vm101" & vbcrlf & _
					"echo ADMINTD" & vbcrlf & _
					"nova start " & vnfName & "vm007" & vbcrlf & _
					"echo AMC" & vbcrlf & _
					"nova start " & vnfName & "vm301" & vbcrlf & _
					"echo VLR" & vbcrlf & _
					"nova start " & vnfName & "vm201" & vbcrlf & _
					"echo SCFE" & vbcrlf & _
					"nova start " & vnfName & "vm121" & vbcrlf & _
					"echo DTDSH" & vbcrlf & _
					"nova start " & vnfName & "vm131" & vbcrlf & _
					"echo DTDRF" & vbcrlf & _
					"nova start " & vnfName & "vm141" & vbcrlf & _
					"echo L4TD" & vbcrlf & _
					"nova start " & vnfName & "vm009" & vbcrlf & _
					"nova start " & vnfName & "vm010" & vbcrlf & _
					"echo SS7" & vbcrlf & _
					"nova start " & vnfName & "vm114" & vbcrlf & _
					"nova start " & vnfName & "vm115"

objStream.Close

crt.Screen.Synchronous = True

Const ForReading = 1

Set file = objFSO.OpenTextFile("C:\Temp\vmList.txt", ForReading, False)

Do While file.AtEndOfStream <> True
	str = file.ReadLine
	crt.Screen.Send str & vbCr
	
	Dim nIndex
    do
        nIndex = crt.screen.WaitForStrings("INFRA", " STORAGE", " OAM", " REPORTING", " ADMINTD", " AMC", " VLR", " SCFE", " DTDSH", " DTDRF", " L4TD", " SS7", "$ ", 20)

        Select Case nIndex
            Case "0"
                MsgBox "Timed out waiting for strings"
                exit do
            Case "12"
                MsgBox "Execute a kgetno to confirm that the above nodes are up."
            Case Else
				Exit Do
        End Select

        crt.sleep 2
    Loop

	
Loop

crt.Screen.Synchronous = False

End Sub


Any ideas welcome,

Bjoern

Last edited by BjoernH; 10-16-2018 at 04:52 PM. Reason: More info
Reply With Quote
  #2  
Old 10-17-2018, 04:50 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 26
Nevermind, it will never work like this.
Reply With Quote
  #3  
Old 10-17-2018, 04:53 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 559
Hi BjoernH,

I'm sorry to hear you're having trouble. I would like to see if I can get a better understanding of how you would like the script to function.

Is there a reason you are writing the commands to a file and reading them back? Perhaps using an array would help make the process a little cleaner. Much of the same functionality would exist without the overhead of creating/reading files.

What is the goal of your Do Loop? It appears any match/timeout expect for Case 12 (SS7) simply exits the loop. Only when a case 12 is found will it loop.

Can you elaborate on what you mean when you say it "stacks the commands before the previous one has finished"? What does this look like?

Would it be possible for you to provide a log of the script running? To ensure we do not accidentally expose sensitive data on the public forums please send the log via email to Support@VanDyke.com with "Attn Eric Forum Post 13290" in the subject line. DO NOT POST THE LOG TO THE FORUMS.

To create the log:
  1. Connect to your session
  2. Choose Log Session in the main File drop down menu
  3. Select a file name/location. I suggest SCRTLog.txt on the Desktop
  4. Run your script
  5. After the script completes disable Log Session in the File menu
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #4  
Old 10-18-2018, 09:46 AM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 26
Thanks for your reply Eric.

At this time, the VMs are not ready for startup, so I've used a different nova command. In fact, once the "nova start <vmName>" command has been issued, there is no output from the server, only the command prompt, "$ "

Ignore the code from my original post, I will email you.

Bjoern
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 02:33 AM.