View Single Post
  #1  
Old 07-27-2012, 09:31 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
How do I ReadString more than 1 screen of output?

I decided to take a break from the larger script I'm working on and use things I've learned from that process to make a smaller script. This smaller script will be used to do a pre-maintenance capture of a device's configuration. The script will be run before and after the maintenance and the two log files can be compared to ensure there was no additional impact beyond what was planned for that maintenence.

Some of the show commands have multiple pages of output. I adapted code to create a subroutine called HitSpace that allows me to capture that data until my command prompt comes back. But I'd like to create some dynamic script to capture all the vlans, and then do commands to show the MAC addresses associated with each vlan. But I can't get the code to play nice.

I have this code:

Code:
crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : crt.Screen.WaitForString vbCr
strVLAN1Output = crt.Screen.ReadString ("#")
Some sample output of the command run with that code:

Code:
HOSTNAME1# show sw 2.1
VLAN Information:
index   type      name	        role
------- --------- ------------- -----------
525     ieee8021d Customer 1	N/A
538     ieee8021d Customer 2	N/A
701     ieee8021d Customer 3	N/A
765     ieee8021d Customer 4	N/A
1051    ieee8021d Customer 5	N/A
1053    ieee8021d Customer 6	N/A
1055    ieee8021d Customer 7	N/A
1057    ieee8021d Customer 8	N/A
1066    ieee8021d Customer 9	N/A
1080    ieee8021d Customer 10	N/A
The problem comes when there are more VLANs that can fit on the screen. The crt.Screen.ReadString ("#") doesn't allow me to call my HitSpace subroutine. I've tried a few combinations, none have worked:

Code:
crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : crt.Screen.WaitForString vbCr
call HitSpace : strVLAN1Output = crt.Screen.ReadString ("#")

crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : call HitSpace
crt.Screen.WaitForString vbCr : strVLAN1Output = crt.Screen.ReadString ("#")

crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : crt.Screen.WaitForString vbCr
strVLAN1Output = crt.Screen.ReadString ("#") : call HitSpace

crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : crt.Screen.WaitForString vbCr
strVLAN1Output = crt.Screen.ReadString (call HitSpace)
... any thoughts?

In case you need it, here's the subroutine:

Code:
Sub HitSpace

' hit space until you get back to #
Do
    nIndex = crt.Screen.WaitForStrings("quit)", "#")
    Select Case crt.Screen.MatchIndex
        Case 1
            ' Found "quit)"
            crt.Screen.Send " "
            
        Case 2
            ' Found "#"
            crt.Screen.Send vbcr
            ' Exit Do..Loop since we have handled all possible cases
            Exit Do
            
    End Select
Loop

End Sub
Thanks in advance
Reply With Quote