Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Old 04-11-2018, 08:45 AM
respite respite is offline
Registered User
Join Date: May 2017
Posts: 6
Script only running on a few hosts at a time

Hello again,

I've been tasked with polling all of our branch Cisco switches for their iOS version and deploy a patch to them after.

My problem is, for whatever reason, my script seems to only want to run on two "vHosts" at once before just sitting there and not obeying the "crt.Session.disconnect" command. When the script stops, I have to manually disconnect the session, then the script will proceed. Any ideas? Script is below.

*Note: there will be many more hosts than just the ones listed, about 900 more*

#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True

on error resume next

Dim vHosts(1000)

vHosts(0) = ""
vHosts(1) = ""
vHosts(2) = ""
vHosts(3) = ""
vHosts(4) = ""
vHosts(5) = ""
vHosts(6) = ""

For Each strHost In vHosts
 If strHost = "" Then Exit For

 ' Make sure we are disconnected before attempting a connection
 If crt.Session.Connected Then crt.Session.Disconnect
  Dim logfile
  logfile = "C:\Users\nmorra\Documents\Scripts\logs\switch-version.log"
  crt.Session.LogFileName = logfile
  crt.Session.Log True, True

 ' Connect to the next host
 crt.Session.Connect "/SSH2 /L * /PASSWORD * " & strHost

	crt.Screen.WaitForString "#"
	crt.Screen.Send "sh version | inc Cisco IOS Software" & chr(13)
	crt.Screen.WaitForString "#"
	crt.Screen.Send "quit" & chr(13)
Reply With Quote
Old 04-11-2018, 09:12 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
Join Date: Jan 2017
Posts: 654
Hi respite,

I'm sorry you're having trouble. Without being able to review the output of the commands it will be difficult for me to diagnose the issue. It could be something as simple as the script not finding the second # and therefore not being able to proceed to sending the quit.

We do have an example script that seems like it would give you the functionality you're looking for. The script 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.

If you would like to try this script it can be found here.

VanDyke Software
Technical Support
(505) 332-5730
Reply With Quote
Old 04-11-2018, 10:49 AM
respite respite is offline
Registered User
Join Date: May 2017
Posts: 6
You're correct!

It wasn't seeing my last "#"
I diagnosed this by moving the crt.session.disconnect command above the last crt.screen.waitforstring.

It didn't matter because I was just exiting at that point anyway.

Everything is working now.

Having said that, I will use the layout you provided as it's much neater. Writing 900 vhosts within the script file is just too messy.

I'll let you know if I have further issues.

Thanks as always for the prompt reply!!
Reply With Quote

hang , multiple-hosts , poll

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 03:56 AM.