VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   How do I ReadString more than 1 screen of output? (https://forums.vandyke.com/showthread.php?t=10599)

emailsbecker 07-27-2012 09:31 AM

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 :)

emailsbecker 07-27-2012 09:41 AM

PS - Unfortunately the device in question does not have a command to allow for unpaginated output (a la Cisco's "term len 0" or Juniper " | no-more") otherwise I would've done that.

rtb 07-27-2012 11:09 AM

Hi emailsbecker,

Thanks for the update. Have you considered using the Get2() method of the Screen object?

It seems like you could use Get2() in each case to capture and concatenate the output. You would use the method just prior to sending space in the first case, and in the second case, you would use it just prior to exiting the loop.

As a note, you would want to use a global variable to make the data available in the main sub-routine. Additionally, you may want to use the CurrentRow and CurrentColumn properties. For example:
Code:

strOutput = Get2(1, 1, CurrentRow, CurrentColumn)

emailsbecker 07-27-2012 12:54 PM

I suppose I would have to do another WaitForStrings ("quit)", "#") and use case ... if I get "quit" then ... well, no, that won't work either. If I get "quit" I can use the Get2 command but if I get the "#" that last page will be a partial page. Get won't work (because I won't know where to start and end the Get) and neither would crt.Screen.ReadString because the data's already been written to the screen.

Any other way I could do this? (I guess you could consider this an official request for a SecureCRT command that combines these abilities.)

(EDIT: removed my question about HitSpace and behavior as if "crt.Screen.Synchronous = False" ... I found the problem.)

emailsbecker 07-27-2012 02:21 PM

HA! Got it. I changed this line:

Code:

  crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr : crt.Screen.WaitForString vbCr
  strVLAN1Output = crt.Screen.ReadString ("#")
  vVLAN1s = Split(strVLAN1Output, vbcrlf)

To this:

Code:

  crt.Screen.Send "show sw " & strBoard(x) & ".1" & vbCr & "  " : crt.Screen.WaitForString vbCr
  strVLAN1Output = crt.Screen.ReadString ("#")
  vVLAN1s = Split(strVLAN1Output, vbcrlf)

It's subtle but the difference is that it sends the command, hits enter, then hits the space bar twice. It still reads until it finds the "#" so it captures what I need.

rtb 07-27-2012 03:22 PM

Hi emailsbecker,

I think that there is a better example of how to deal with devices that force paging in the scripting manual at the following location:
http://www.vandyke.com/support/tips/...ing/index.html
The example starts on page 51, but the explanation of the example begins on page 50. The ReadString() method already does what you want. I forgot about this example prior posting my suggestion on using Get2().

Does the example help you accomplish your goal?

emailsbecker 07-27-2012 03:49 PM

Yes! I'd read that and forgotten about it. I did find a snip of code via Google that had multiple strings in Readstring group but they weren't using them properly and so that didn't help me. But for future reference hopefully I'll remember the example from the scripting guide.

rtb 07-27-2012 03:52 PM

Hi emailsbecker,

I am glad that the example helped. If you do forget in the future, just remember that I forgot, and I do this every day:)

Have a great weekend.


All times are GMT -6. The time now is 01:59 AM.