View Single Post
  #1  
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*



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

crt.Screen.Synchronous = True

on error resume next

Dim vHosts(1000)

vHosts(0) = "172.26.36.5"
vHosts(1) = "172.26.36.50"
vHosts(2) = "172.27.100.50"
vHosts(3) = "172.27.100.5"
vHosts(4) = "172.30.10.5"
vHosts(5) = "172.30.10.6"
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)
	crt.Session.disconnect
Reply With Quote