Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-22-2010, 01: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, 01: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, 341 views)
Reply With Quote
  #3  
Old 10-22-2010, 07: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, 03: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, 04: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, 05: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
  #7  
Old 10-27-2010, 05:13 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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.
Attached Files
File Type: zip Capture-Serial-Numbers-to-Excel-v2.zip (2.1 KB, 341 views)
Reply With Quote
  #8  
Old 10-27-2010, 06:31 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Quote:
I am assuming there is a string length problem unless the MsgBox is not showing the entire string
MsgBox does have a string length limit.

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:
  1. Before connecting with the session, select "Raw Log Session" from SecureCRT's "File" menu.
  2. In the "Select Log File" dialog, choose a folder and filename in which you would like the log text to be stored and press the "Save" button. At this point, if you open the "File" menu, you will notice that the "Raw Log Session" menu item now has a check-mark next to it; this indicates that raw logging is activated.
  3. Now connect to the remote machine and perform the actions which cause the reported problem to occur.
  4. Once the problem occurs, disconnect the session and select "Raw Log Session" from the "File" menu to turn off the raw logging feature.
  5. Browse to the location of the raw log file and add the file as an attachment to your e-mail reply.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #9  
Old 10-27-2010, 06:53 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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.
Attached Files
File Type: zip logs.zip (4.0 KB, 327 views)
Reply With Quote
  #10  
Old 10-27-2010, 11:22 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Emailed

I just emailed the raw logs.
Reply With Quote
  #11  
Old 10-28-2010, 09:25 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
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]
Reply With Quote
  #12  
Old 11-08-2010, 02:43 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Uploaded the Vb Script

I've uploaded the VB Script again. If you see an "option" ignore it, it's commented out.
Attached Files
File Type: zip Capture-Serial-Numbers-to-Excel-v2.zip (2.1 KB, 322 views)
Reply With Quote
  #13  
Old 11-09-2010, 07:54 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
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]
Reply With Quote
  #14  
Old 01-11-2011, 12:23 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
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
Attached Files
File Type: zip Capture-Serial-Numbers-to-Excel-v16.zip (1.6 KB, 329 views)
Reply With Quote
  #15  
Old 01-11-2011, 03:00 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 12:28 AM.