Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping trough array looking for matching words

Status
Not open for further replies.

007700

Programmer
Jan 24, 2005
20
NL
Hi there,

I am currently writing a script that will analyse the output of a cisco device.
From the device I get the output of the Show Diag command. It produces something like show below.
Code:
VHN_1101_1#sh diag
Slot 0:
        Combo 2E, 2W Port adapter, 4 ports
        Port adapter is analyzed
        Port adapter insertion time unknown
        EEPROM contents at hardware discovery:
        Hardware revision 1.2           Board revision A0
        Serial number     8837704       Part number    800-01171-05
        FRU Part Number:  NM-2E2W=

        Test history      0x0           RMA number     00-00-00
        EEPROM format version 1
        EEPROM contents (hex):
          0x00: 01 1E 01 02 00 86 DA 48 50 04 93 05 00 00 00 00
          0x10: 50 00 00 00 98 05 19 17 FF FF FF FF FF FF FF FF

        WIC Slot 0:
        Serial 1T WAN daughter card
        Hardware revision 1.1           Board revision E0
        Serial number     8328657       Part number    73-1775-02
        Test history      0x0           RMA number     00-00-00
        Connector type    Wan Module
        EEPROM format version 1
        EEPROM contents (hex):
          0x20: 01 02 01 01 00 7F 15 D1 49 06 EF 02 00 00 00 00
          0x30: 70 00 00 00 98 05 22 01 FF FF FF FF FF FF FF FF

        WIC Slot 1:
        Serial 1T WAN daughter card
        Hardware revision 1.1           Board revision E0
        Serial number     8330349       Part number    73-1775-02
        Test history      0x0           RMA number     00-00-00
        Connector type    Wan Module
        EEPROM format version 1
        EEPROM contents (hex):
          0x20: 01 02 01 01 00 7F 1C 6D 49 06 EF 02 00 00 00 00
          0x30: 70 00 00 00 98 05 26 01 FF FF FF FF FF FF FF FF

Slot 1:
        NM-1FE1R2W Port adapter, 2 ports
        Port adapter is analyzed
        Port adapter insertion time unknown
        EEPROM contents at hardware discovery:
        Hardware Revision        : 1.0
        Top Assy. Part Number    : 800-04798-01
        Board Revision           : E0
        Deviation Number         : 0-6158
        Fab Version              : 04
        PCB Serial Number        : JAB04260BCB
        RMA Test History         : 00
        RMA Number               : 0-0-0-0
        RMA History              : 00
        EEPROM format version 4
        EEPROM contents (hex):
          0x00: 04 FF 40 00 D9 41 01 00 C0 46 03 20 00 12 BE 01
          0x10: 42 45 30 80 00 00 18 0E 02 04 C1 8B 4A 41 42 30
          0x20: 34 32 36 30 42 43 42 03 00 81 00 00 00 00 04 00
          0x30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

        WIC Slot 0:
        DSL SAR (ADSL)

        Hardware Revision        : 2.3
        Part Number              : 73-4771-08
        Board Revision           : B0
        Deviation Number         : 1-200
        Fab Version              : 05
        PCB Serial Number        : FOC072307U6
        RMA Test History         : 00
        RMA Number               : 0-0-0-0
        RMA History              : 00
        EEPROM format version 4
        EEPROM contents (hex):
          0x00: 04 FF 40 00 2E 41 02 03 82 49 12 A3 08 42 42 30
          0x10: 80 00 01 00 C8 02 05 C1 8B 46 4F 43 30 37 32 33
          0x20: 30 37 55 36 03 00 81 00 00 00 00 04 00 FF FF FF
          0x30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

        WIC Slot 1:
        DSL SAR (GSHDSL/SDSL)

        Hardware Revision        : 1.0
        Top Assy. Part Number    : 800-08279-05
        Board Revision           : D0
        Deviation Number         : 0-0
        Fab Version              : 05
        PCB Serial Number        : JAD07210ANK
        RMA Test History         : 00
        RMA Number               : 0-0-0-0
        RMA History              : 00
        EEPROM format version 4
        EEPROM contents (hex):
          0x00: 04 FF 40 00 35 41 01 00 C0 46 03 20 00 20 57 05
          0x10: 42 44 30 80 00 00 00 00 02 05 C1 8B 4A 41 44 30
          0x20: 37 32 31 30 41 4E 4B 03 00 81 00 00 00 00 04 00
          0x30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
          0x70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

VHN_1101_1#


I put the output into an array and analyse it. Sor instance I am looking for the word "Part number" and getting the value belonging to it. The problem is that my search string might occur more that once, and I don't know how to control which one the program has....

Could anyone help me with this ? How can I control or check where it gets the value in the output ?

For instance in the example above, I first want to start at slot 0 and analyse everything that's in there. When that is finished I want to get the output of slot 1 etc etc
Finally I would also like to separate the modules that are in slot 0 and 1, so in the example above I would get

Slot 0:
module 1: Combo 2E, 2W Port adapter
Part number
module 2: Serial 1T WAN daughter card
Part number
module 3: Serial 1T WAN daughter card
Part number

...any help is greatly appreciated...

Regards from Holland.
 
I put the output into an array and analyse it
And what have you so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
Function Collect_DIAGTable(MyAltCommand)

Dim X
Dim S
Dim E
Dim LOD
Dim Serialnumber
Dim Partnumber

on error resume next

Collect_DIAGTable = ""

If Len(MyAltCommand) > 0 Then
    Cmd = MyAltCommand
Else
    Cmd = "show diag"
End If

If EnterCmdSingle(Cmd, 1, 0) = False Then Exit Function

Buffer = cl.RxBuffer

Serialnumber = ""
Partnumber = ""

LOD = Split(Buffer, vbCrLf)
If UBound(LOD) = -1 Then Exit Function
    For X = 0 To UBound(LOD)
  
      If InStr(LOD(X), "Part number") then
		Cmd = Chassis:
		S = InStr(1, LOD(X), Cmd, vbTextCompare)
		If S > 0 Then
	       Partnumber = Trim(Mid(LOD(X), 15, 12))
		End If
	  End If

       If InStr(LOD(X), "Serial number") then
		Cmd = Location:
		S = InStr(1, LOD(X), Cmd, vbTextCompare)
		If S > 0 Then
	       Serialnumber = Trim(Mid(LOD(X), 18, 10))
		End If
	  End If   
Next


End Function

This is the setup I use, maybe not the best one, but that got the trough different output. The only problem is that over there I did't have a reoccuring search string.
 
Something like this ?
Code:
Function Collect_DIAGTable(MyAltCommand)
Dim Cmd, Buffer, LOD, X, Module
Collect_DIAGTable = ""
If Len(MyAltCommand) > 0 Then
    Cmd = MyAltCommand
Else
    Cmd = "show diag"
End If
If EnterCmdSingle(Cmd, 1, 0) = False Then Exit Function
Buffer = cl.RxBuffer
LOD = Split(Buffer, vbCrLf)
If UBound(LOD) = -1 Then Exit Function
For X = 0 To UBound(LOD)
  If InStr(1, LOD(X), "slot", vbTextCompare) Then
    If Left(LOD(X), 4) = "Slot" Then
      Module = 1
      Collect_DIAGTable = Collect_DIAGTable & LOD(X) & vbCrLf
    Else
      Module = Module + 1
    End If
    X = X + 1
    Collect_DIAGTable = Collect_DIAGTable & "module " & Module & ": " & LOD(X) & vbCrLf
  End If
  If InStr(1, LOD(X), "serial number", vbTextCompare) _
  Or InStr(1, LOD(X), "part number", vbTextCompare) Then
    Collect_DIAGTable = Collect_DIAGTable & "  " & LOD(X) & vbCrLf
    X = X + 1
  End If
Next
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top