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 07-24-2018, 12:27 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 23
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
  #2  
Old 07-24-2018, 01:10 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 501
Hi BjoernH,

We do have an example script that I believe provides much of the functionality you're looking for.

Run Commands On Multiple Hosts And Log Results
Demonstrates how to connect to hosts read in from a "hosts" file and for each host, send a list of commands read in from a "commands" file. Results of each command run are (by default) logged to separate, uniquely-named files based on the host address and the command that is run. However, the script code is architected to allow you to change this behavior so that it's all logged to one file per host, or even just to a single file.

You would only need to create a file, hosts.txt, with the list of IPs and a commands.txt file that contains the list of commands you would like to run. The script would then connect to each device and run the commands specified.

Does this script seem like it would fit your needs or help provide an example you could modify to fit your needs?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-24-2018, 02:20 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 23
Thanks for the reply Eric, however, that script is just massive overkill for my needs, I don't even know how the author manages to ssh to the remote host.

Furthermore, I would prefer to use the IP array as listed in the code.


Regards,
Bjoern
Reply With Quote
  #4  
Old 07-24-2018, 03:40 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 501
BjoernH,

We've tried to make the example script as complete and easy to use as possible to reduce the amount of editing a user would need to do. In most cases you should not have to make any changes to the script, simply provide a file with a list of servers and a file with a list of commands.

That being said, I have taken a look at the code you provided and noticed an issue with your Do Loop. Do Loops run an infinite number of times unless you provide an exit condition. I don't see that there is any exit condition for your Do Loop, the script is getting stuck running the Do Loop forever.

What would be a good indicator that you are done with the first host and ready to move on to the second?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
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 12:13 PM.