#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
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!! |
![]() |
Tags |
hang , multiple-hosts , poll |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|