View Single Post
  #1  
Old 07-24-2018, 12:27 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 41
Vbscript: unable to break out of waitfors loop

Good day.

I've been trying to write this vbscript that is supposed to log into 10 different servers based on the IP array, and extract some information from each. The script compiles, but it remains in a loop on the first server, always looping back to line #34 (crt.Screen.WaitForStrings).

Code:
'#$language = "VBScript"
'#$interface = "1.0"

crt.Screen.Synchronous = True

Sub Main()

Dim vHosts(10)
vHosts (0) = "172.24.16.102"
vHosts (1) = "172.24.16.100"
vHosts (2) = "172.24.16.101"
vHosts (3) = "172.24.16.103"
vHosts (4) = "172.24.16.105"
vHosts (5) = "172.24.16.104"
vHosts (6) = "172.24.16.109"
vHosts (7) = "172.24.16.106"
vHosts (8) = "172.24.16.125"
vHosts (9) = "172.24.16.131"

AuthE = InputBox("Please enter the euser password:","","*")
	If AuthE = ""  Then Exit Sub
	
For Each strHosts In vHosts
    If strHosts = "" Then Exit For
	
    crt.Screen.Send"ssh euser@" & strHosts & vbCr

Dim vWaitFors
vWaitFors = Array("(yes/no)?", _
					"assword:")

Do
	Dim nResult
	nResult = crt.Screen.WaitForStrings(vWaitFors, 5)

	Select Case nResult

		Case 1
		
			crt.Screen.Send"yes" & vbCr
		
		Case 2
		
			crt.Screen.Send AuthE & vbCr
			
		Case Else
		
	crt.Screen.Send"echo;hostname;ip a|grep int-oam;echo" & vbCr
	crt.Screen.WaitForString"~]$"

	end Select

Loop
	crt.Screen.Send"exit" & vbCr

Next
	
End Sub

Any help or pointers appreciated.


Thanks in advance,
Bjoern
Reply With Quote