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 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
  #2  
Old 07-27-2012, 09:41 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
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.
Reply With Quote
  #3  
Old 07-27-2012, 11:09 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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)
__________________
--Todd

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

Last edited by rtb; 07-27-2012 at 11:34 AM.
Reply With Quote
  #4  
Old 07-27-2012, 12:54 PM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
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.)

Last edited by emailsbecker; 07-27-2012 at 02:08 PM.
Reply With Quote
  #5  
Old 07-27-2012, 02:21 PM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
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.
Reply With Quote
  #6  
Old 07-27-2012, 03:22 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 07-27-2012, 03:49 PM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
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.
Reply With Quote
  #8  
Old 07-27-2012, 03:52 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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.
__________________
--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 09:37 AM.