#1
|
|||
|
|||
![]()
Hello,
I am having an issue with running vbtextcompare within a string. The dim specified cannot be defined "dim xxx As String". Because it is not specified as a string securecrt throws a "type error" when it reaches that line. I have since tried "Option Explicit On" and "dim xxx As String" with not success. Any way you can take a look? I've attached the script. Oh and the goal of the script is telnetting into a entered array of ip addresses, sending a "show version" once connected and reading the serial numbers from the devices. Then the script dumps the serial numbers into excel. The hiccup is occuring at the 2nd sub-section which specifies the actions of pulling multiple serial numbers from a stack of switches. (Cisco switch stacks are joined with backplane cables and act as one switch from the command line. When you enter a "show version" on a switch stack it outputs all the switch serial numbers.) I want the vbtextcompare to find the "System serial number : " text and count how many times that text is found. That will specify how many switches are in the stack and therefore how many times to loop the serial number extraction section. Thanks! olivebranch2006 |
#2
|
|||
|
|||
Script Upload
The script did not upload, uploading as a zip file.
olivebranch2006 |
#3
|
||||
|
||||
Hello olivebranch2006,
Quote:
Code:
showver = crt.Screen.ReadString(register) switchcount = InStr(showver, "System serial number : ", vbTextCompare) showver = crt.Screen.ReadString("register")You also said want to count the number of times "System serial number" appears. The InStr method returns the position of the first occurrence of one string within another. InStr does not count the number of occurrences. To count the number of occurences, a couple of ideas come to mind:
It looks like your code is putting the output from ReadString into the variable showver. If you use a regular expression to search showver, the code may resemble the following pseudo code. Code:
' Create a new regular expression object Set re = New RegExp re.Pattern = "System serial number.*\:" If re.Test(showver) <> True Then MsgBox "Pattern " & re.Pattern & " not found" Else Set matches = re.Execute(showver) MsgBox "Number of matches found: " & matches.Count End If
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#4
|
|||
|
|||
Reply to Questions
The first line looks a little suspicious because register is not declared as a variable anywhere, and is not passed as a string. Did you mean to declare it as a variable, or are you wanting to read data until you see the string "register", as shown below?
showver = crt.Screen.ReadString("register") To answer this, this reads data until it sees the string "register". This part does work, I tested it with a msgbox. You also said want to count the number of times "System serial number" appears. The InStr method returns the position of the first occurrence of one string within another. InStr does not count the number of occurrences. You are correct, I did not know how to accomplish this and chose the wrong method (InStr) It looks like your code is putting the output from ReadString into the variable showver. If you use a regular expression to search showver, the code may resemble the following pseudo code. The regular expression search sounds like a good way. I will add your pseudo code and try it out. Thanks! |
#5
|
|||
|
|||
Problem
So far it is working but the "showver" string is not capturing the entire string of characters as defined by crt.screen.readstring("register")
It only captures: *1 Master 3cdf.1e12.bc00 10 1 Ready 2 Member f4ac.c1d7.d580 5 0 Ready 3 Member f4ac.c1d2.b280 1 0 Ready EV-IDF1-RmA119-3750Stack#show version Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(52)SE, RELEASE SOFTWARE (fc3) Copyright (c) 1986-2009 by Cisco Systems, Inc. Compiled Fri 25-Sep-09 07:33 by sasyamal Image text-base: 0x00003000, data-base: 0x02400000 ROM: Bootstrap program is C3750E boot loader BOOTLDR: C3750E Boot Loader (C3750E-HBOOT-M) Version 12.2(44r)SE3, RELEASE SOFTWARE (fc3) EV-IDF1-RmA119-3750Stack uptime is 40 weeks, 1 day, 36 minutes System returned to ROM by power-on System restarted at 13:35:27 pst Tue Jan 19 2010 System image file is "flash:c3750e-universalk9-mz.122-52.SE/c3750e-universalk9-mz.122-52.SE.bin" This product contains cryptographic features and is subject to But needs to capture all this: Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(52)SE, RELEASE SOFTWARE (fc3) Copyright (c) 1986-2009 by Cisco Systems, Inc. Compiled Fri 25-Sep-09 07:33 by sasyamal Image text-base: 0x00003000, data-base: 0x02400000 ROM: Bootstrap program is C3750E boot loader BOOTLDR: C3750E Boot Loader (C3750E-HBOOT-M) Version 12.2(44r)SE3, RELEASE SOFTWARE (fc3) EV-IDF1-RmA119-3750Stack uptime is 40 weeks, 1 day, 36 minutes System returned to ROM by power-on System restarted at 13:35:27 pst Tue Jan 19 2010 System image file is "flash:c3750e-universalk9-mz.122-52.SE/c3750e-universalk9-mz.122-52.SE.bin" This product contains cryptographic features and is subject to United States and local country laws governing import, export, transfer and use. Delivery of Cisco cryptographic products does not imply third-party authority to import, export, distribute or use encryption. Importers, exporters, distributors and users are responsible for compliance with U.S. and local country laws. By using this product you agree to comply with applicable laws and regulations. If you are unable to comply with U.S. and local laws, return this product immediately. A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending email to export@cisco.com. License Level: ipbase License Type: Permanent Next reload license Level: ipbase cisco WS-C3750E-48PD (PowerPC405) processor (revision F0) with 262144K bytes of memory. Processor board ID FDO1344R0LY Last reset from power-on 2 Virtual Ethernet interfaces 1 FastEthernet interface 156 Gigabit Ethernet interfaces 2 Ten Gigabit Ethernet interfaces The password-recovery mechanism is enabled. 512K bytes of flash-simulated non-volatile configuration memory. Base ethernet MAC Address : 3C ![]() Motherboard assembly number : 73-11174-13 Motherboard serial number : FDO13440TSQ Model revision number : F0 Motherboard revision number : A0 Model number : WS-C3750E-48PD-S Daughterboard assembly number : 800-29737-01 Daughterboard serial number : FDO13440HSB System serial number : FDO1344R0LY Top Assembly Part Number : 800-28916-01 Top Assembly Revision Number : B0 Version ID : V03 CLEI Code Number : COM9W10ARB Hardware Board Revision Number : 0x00 Switch Ports Model SW Version SW Image ------ ----- ----- ---------- ---------- * 1 54 WS-C3750E-48PD 12.2(52)SE C3750E-UNIVERSALK9-M 2 52 WS-C3750G-48TS 12.2(52)SE C3750-IPBASEK9-M 3 52 WS-C3750G-48TS 12.2(52)SE C3750-IPBASEK9-M Switch 02 --------- Switch Uptime : 40 weeks, 1 day, 14 minutes Base ethernet MAC Address : F4:AC:C1 ![]() ![]() Motherboard assembly number : 73-10218-08 Power supply part number : 341-0107-01 Motherboard serial number : FOC134334BA Power supply serial number : AZS1341039T Model revision number : F0 Motherboard revision number : E0 Model number : WS-C3750G-48TS-S System serial number : FOC1343Y1R2 Top assembly part number : 800-26857-02 Top assembly revision number : C0 Version ID : V04 CLEI Code Number : COM7X10ARA Switch 03 --------- Switch Uptime : 40 weeks, 1 day, 14 minutes Base ethernet MAC Address : F4:AC:C1 ![]() Motherboard assembly number : 73-10218-08 Power supply part number : 341-0107-01 Motherboard serial number : FOC13433KBM Power supply serial number : AZS134103DS Model revision number : F0 Motherboard revision number : E0 Model number : WS-C3750G-48TS-S System serial number : FOC1343Y1T2 Top assembly part number : 800-26857-02 Top assembly revision number : C0 Version ID : V04 CLEI Code Number : COM7X10ARA Configuration register is 0xF Is there a limit to the string length? Thanks! |
#6
|
|||
|
|||
string length
I am assuming there is a string length problem unless the MsgBox is not showing the entire string?
When the script is run it also states: number of matches found: 1 And it should be three. I'm online now if you would like to troubleshoot it right now... |
#7
|
|||
|
|||
Upload
Here is the latest copy of the script.
Can the string length be increased with a "Dim showver as var" or something similar? I thought strings are variable length by default and they can be up to 2 billion characters or the limitation of the amount of RAM. |
#8
|
||||
|
||||
Quote:
Can you send a raw log file to support@vandyke.com so that I can run some tests with your most current code? To create a raw log:
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#9
|
|||
|
|||
Raw Log Captures
I've attached two logs. One labeled "typing-commands" is me telnetting into the switch and typing the "show version" command which I want to input into a string. Another labeled "Running-Script" which is the same process running through the script.
|
#10
|
|||
|
|||
Emailed
I just emailed the raw logs.
![]() |
#11
|
||||
|
||||
Thanks,
We received your e-mail. I'll run some tests with your script and log file and see if I can help you find the cause of the problem.
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#12
|
|||
|
|||
Uploaded the Vb Script
I've uploaded the VB Script again. If you see an "option" ignore it, it's commented out.
|
#13
|
||||
|
||||
I'm reviewing your code and running tests. If there is different test data than before, please send a raw log via e-mail.
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#14
|
|||
|
|||
Working Code
I know we had some emails off-forum so here is the semi-working script... It works by grabbing the first ip address from Excel's 6th column, row 4. My ip addresses are listed in that column and the script will ssh to the ip, perform commands and extract data to strings, write the data to the hostname and S/N columns, exit the device, ssh to the next ip and loop this until it has a row with no ip address(essentially the end of the list).
But there is some strange behavior... ![]() It has no trouble reading the ip addresses, ssh into them, find hostname and serial, I know this because of watching the securecrt terminal and then seeing the msgbox tell me the serial number every time. It also places the hostname correctly in every hostname column cell sequentially. It only writes two serial number strings in, (one in row 4, one in row 5) and then never writes a serial number again. Is this a vbscript limitation? bad code? Every excel vbscript code example I've seen on the net shows writing to cells this same way and you should have access to any cell number in the sheet. Any ideas? Thanks olivebranch2006 Christo |
#15
|
|||
|
|||
Hi Christo,
I looked at v16 of your script, and did not see anything in the code that would result in data not being written to the Excel spreadsheet. One suggestion would be to confirm that the data being written to the Excel spreadsheet in rows after 5 is formatted to have text the same color as the background. This may not be the only formatting issue. Another suggestion would be to place your message box after you write the serial number to the spreadsheet, so you can see what was written. Further, you could have a message box telling you what is about to be written, and then another that reads what is written. If this doesn't help, another option is to use strategically placed message boxes in your code to determine what certain variables contain at certain points, to help ensure that what you think is happening is really happening. Another option would be to write to a comma delimited file, and see if you get the data you expect. It is also possible that because you are not saving the Excel spreadsheet, the data is lost. Finally, you may want to step through your script using a debugger to see what might be happening. Do these suggestions help debug your script? |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|