Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-22-2010, 12:24 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Lightbulb vbtextcompare and string issue

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
Reply With Quote
  #2  
Old 10-22-2010, 12:27 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Script Upload

The script did not upload, uploading as a zip file.

olivebranch2006
Attached Files
File Type: zip CaptureSerialNumbers.zip (2.0 KB, 506 views)
Reply With Quote
  #3  
Old 10-22-2010, 06:14 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hello olivebranch2006,
Quote:
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.
The following lines of code looks like they might need to be changed:
Code:
    showver = crt.Screen.ReadString(register)
    switchcount = InStr(showver, "System serial number            : ", vbTextCompare)
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")
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:
  • Use the VBScript Split function to split the showver variable into an array. You could use a carriage return as the delimiter. After showver is split into an array you could loop through every element and use InStr to see whether each element contains "System serial number".
  • Use a regular expression to search the showver variable. You can use the regular expression method Count to tell you how many matches were found.
The SecureCRT Scripting Manual has a regular expression example in section 4.3 Capturing Data from a Remote Machine (near page 53) which shows how to use a regular expression to do something similar to what you're wanting to do.

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]
Reply With Quote
  #4  
Old 10-27-2010, 02:30 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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!
Reply With Quote
  #5  
Old 10-27-2010, 03:54 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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 : 3CF:1E:12:BC:00
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:C175:80
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:C12:B2:80
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!
Reply With Quote
  #6  
Old 10-27-2010, 04:09 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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...
Reply With Quote
Reply

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 11:23 AM.