#1
|
|||
|
|||
![]()
Hello All,
Forgive me, I'm a little new to scripting with CRT. I'm trying to connect to a bunch of hosts and return only one line to a log file instead of printing the entire output from my command. I want to be able to return the line that says AP-51xx firmware version : 2.3.2.0-008R as I'm specifically looking for for the model, in this case "AP-51xx". We have a few more models than that, I'll be scanning a few hundred devices and would like to be able to say "IP 172.xx.yyy.14x has model APxxxx" if that makes sense. Here is the script.. #$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True on error resume next ' Make sure we are disconnected before attempting a connection If crt.Session.Connected Then crt.Session.Disconnect ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ crt.Session.Connect "/SSH2 /ACCEPTHOSTKEYS /L ****** /PASSWORD ******* 172.26.25.140" ' Do work on the remote machine. crt.session.logfilename="APType_Poll_Output.log" crt.session.log TRUE, TRUE crt.Screen.WaitForString "admin>" crt.Screen.Send "sum" & chr(13) crt.Screen.WaitForString "admin>" crt.Screen.Send "quit" & chr(13) crt.Session.Disconnect crt.session.log False ' Disconnect before moving on to the next host crt.Session.Disconnect crt.Session.Connect "/SSH2 /ACCEPTHOSTKEYS /L ****** /PASSWORD ****** 172.26.57.140" ' Do work on the remote machine. crt.session.logfilename="APType_Poll_Output.log" crt.session.log TRUE, TRUE crt.Screen.WaitForString "admin>" crt.Screen.Send "sum" & chr(13) crt.Screen.WaitForString "admin>" crt.Screen.Send "quit" & chr(13) crt.Session.Disconnect crt.session.log False Here is the messy output. Note: Irrelevant/Sensitive data has been scrubbed. admin>sum AP-51xx firmware version : 2.3.2.0-008R country code : ca ap-mode : independent serial number : ********** WLAN 1: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default WLAN 2: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default WLAN 3: WLAN name : ####### ESS ID : ####### Radio : 11b/g VLAN : ###### Security Policy : ####### QoS Policy : Default WLAN 4: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default LAN1 Name: LAN1 LAN1 Mode: enable LAN1 IP: 172.26.25.140 LAN1 Mask: 255.255.255.0 LAN1 DHCP Mode: static LAN2 Name: LAN2 LAN2 Mode: disable LAN2 IP: 192.168.1.1 LAN2 Mask: 255.255.255.0 LAN2 DHCP Mode: static WAN Interface IP Address Network Mask Default Gateway DHCP Client ------------------------------------------------------------------------------ disable 10.1.1.1 255.0.0.0 0.0.0.0 disable admin>sum AP-51xx firmware version : 2.3.2.0-008R country code : ca ap-mode : independent serial number : *************** WLAN 1: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default WLAN 2: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default WLAN 3: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default WLAN 4: WLAN name : ###### ESS ID : ###### Radio : 11b/g VLAN : ###### Security Policy : ###### QoS Policy : Default LAN1 Name: LAN1 LAN1 Mode: enable LAN1 IP: 172.26.57.140 LAN1 Mask: 255.255.255.0 LAN1 DHCP Mode: static LAN2 Name: LAN2 LAN2 Mode: disable LAN2 IP: 192.168.1.1 LAN2 Mask: 255.255.255.0 LAN2 DHCP Mode: static WAN Interface IP Address Network Mask Default Gateway DHCP Client ------------------------------------------------------------------------------ disable 10.1.1.1 255.0.0.0 0.0.0.0 disable Help is greatly appreciated |
#2
|
|||
|
|||
Hi respite,
I'm glad to hear you are exploring SecureCRT automation abilities. I've included a brief example of one way this may be accomplished. Code:
# $language = "VBScript" # $interface = "1.0" crt.screen.synchronous = true Set g_fso = CreateObject("Scripting.FileSystemObject") Set objFile = g_fso.OpenTextFile("C:\Users\<user>\Desktop\Log.txt", 8, True) crt.screen.WaitForString("AP-") strText = crt.screen.ReadString(vbcrlf) crt.screen.WaitForString("LAN1 IP: ") strIP = crt.screen.ReadString(vbcrlf) objFile.Write strIP & " has model AP-" & strText & vbcrlf objFile.Close Does this help?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Hey
Thanks for the quick reply! I see the logic but I seem to be missing something... The script is connecting and executing commands but doesn't seem to be logging/searching the variables correctly. In my logfile "AP_Scan_Type_Log.txt" It only shows has model AP- with nothing else in the text file. No IPs or model numbers. Here is the updated code: (I've cleaned up how it connects to the hosts, as I'm reading your manuals lol) Quote:
|
#4
|
|||
|
|||
Hi respite,
I found a few timing issues but with a little modification it looks like you may have a solution. With the modification I've made does it run as expected? Code:
# $language = "VBScript" # $interface = "1.0" Sub Main() crt.screen.synchronous = true on error resume next Dim vHosts(100) vHosts(0) = "172.26.25.140" vHosts(1) = "172.26.37.140" vHosts(2) = "172.26.24.140" vHosts(3) = "172.26.94.140" vHosts(4) = "172.26.203.140" vHosts(5) = "172.26.100.140" vHosts(6) = "172.26.103.140" vHosts(7) = "172.26.56.140" vHosts(8) = "172.26.132.140" vHosts(9) = "172.26.60.140" vHosts(10) = "" For Each strHost In vHosts If strHost = "" Then Exit Sub End If ' Make sure we are disconnected before attempting a connection If crt.Session.Connected Then crt.Session.Disconnect ' Connect to the next host crt.Session.Connect "/SSH2 /ACCEPTHOSTKEYS /L ******* /PASSWORD ******* " & strHost crt.Screen.WaitForString "admin>" crt.Screen.Send "sum" & chr(13) Set g_fso = CreateObject("Scripting.FileSystemObject") Set objFile = g_fso.OpenTextFile("C:\Users\nmorra\Documents\Scripts\logs\AP_Scan_Type_Log.txt", 8, True) crt.screen.WaitForString("AP-") strText = crt.screen.ReadString(vbcrlf) crt.screen.WaitForString("LAN1 IP: ") strIP = crt.screen.ReadString(vbcrlf) objFile.Write strIP & " has model AP-" & strText & vbcrlf objFile.Close crt.Screen.WaitForString "admin>" crt.Screen.Send "quit" & chr(13) crt.Session.Disconnect Next End Sub
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
Eric, my man!
Works perfect! Thank you so much. I have one last question. I have a line that says "on error resume next" I'm looking for a way to continue on to the next host but to write a log of failures with which host failed. This way I can look at them individually. Is that easy, or? Thanks again! |
#6
|
|||
|
|||
Hi respite,
Glad to hear that is working for you so far. Our scripting manual covers some of the considerations when trying to handle errors. I suggest reviewing the "helper functions". I believe the best way of handling errors would require modifying the code quite a bit. If you have any specific questions please feel free to let me know.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
|||
|
|||
Thanks I got my error logging working!
|
#8
|
|||
|
|||
respite,
Glad to hear it. Have a great rest of the day.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
log file , output , ssh |
Thread Tools | |
Display Modes | Rate This Thread |
|
|