Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-15-2013, 09:05 PM
Monte.Tucker Monte.Tucker is offline
Registered User
 
Join Date: Sep 2005
Location: Phoenix, AZ
Posts: 33
Read and Show Details

I am trying to write a vbs script for a button that will show the below, and capture each interface name. Then send a show interface detail <int name> for each interface.

Code:
(controller1)>
(controller1)>show interface summary

Interface Name                  Port Vlan Id  IP Address      Type    Ap Mgr Guest
------------------------------- ---- -------- --------------- ------- ------ -----
ap-manager                      LAG  untagged 10.100.100.112  Static  Yes    No
interface01                     LAG  115      10.100.115.111  Dynamic No     No
interface02                     LAG  116      10.100.116.111  Dynamic No     No
interface03                     LAG  117      10.100.117.111  Dynamic No     No
interface04                     LAG  118      10.100.118.111  Dynamic No     No
interface05                     LAG  119      10.100.119.111  Dynamic No     No
interface06                     LAG  120      10.100.120.111  Dynamic No     No
interface07                     LAG  121      10.100.121.111  Dynamic No     No
management                      LAG  untagged 10.100.100.111  Static  No     No
service-port                    N/A  N/A      0.0.0.0         Static  No     No
virtual                         N/A  N/A      1.1.1.1         Static  No     No
interface08                     LAG  122      10.100.122.111  Dynamic No     No
interface09                     LAG  123      10.100.123.111  Dynamic No     No
interface10                     LAG  124      10.100.124.111  Dynamic No     No
interface11                     LAG  125      10.100.125.111  Dynamic No     No

Would you like to dispay the next 15 entries? (y/n) y


Interface Name                  Port Vlan Id  IP Address      Type    Ap Mgr Guest
------------------------------- ---- -------- --------------- ------- ------ -----
interface12                     LAG  126      10.100.126.111  Dynamic No     No
interface12                     LAG  127      10.100.127.111  Dynamic No     No

(controller1)>show interface detail interface ap-manager
<output>
(controller1)>show interface detail interface interface01
<output>
and so on until end of the list. I would also need to look for the y/n and enter y.

I've tried this with the dictionary approach, but I'm about to try again with an array. I was also looking at using a RegEx and trim() to capture the interface name.

Do you already have something like this in your inventory?

Thanks,
Monte
Reply With Quote
  #2  
Old 05-16-2013, 10:23 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Monte,

We do not have an example script that meets your needs exactly. The scripting manual explains how you can parse data in chapter 4.3. You can find the scripting manual at the following location:
http://www.vandyke.com/support/tips/...ing/index.html
Do you have a specific question I can help answer?

What particular part of your script are you having difficulty writing?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 05-16-2013, 11:04 AM
Monte.Tucker Monte.Tucker is offline
Registered User
 
Join Date: Sep 2005
Location: Phoenix, AZ
Posts: 33
read into array or dictionary

I wanted to read each line into an array with something like this:

Code:
x = 0
crt.Screen.Send "show interface summary" & VbCr
crt.Screen.WaitForString VbCr
do
  strResult = crt.Screen.ReadString("y/n", strPrompt)
  If crt.Screen.MatchIndex = 1 Then crt.Screen.Send "y"
  If crt.Screen.MatchIndex = 2 Then Exit Do
  vIntout(x,0) = split(strResult, " ")
  x = x + 1
loop
The strResult gets the whole screen of the output, but the array is not getting populated.
Reply With Quote
  #4  
Old 05-16-2013, 12:47 PM
Monte.Tucker Monte.Tucker is offline
Registered User
 
Join Date: Sep 2005
Location: Phoenix, AZ
Posts: 33
Mostly solved

I have the solution, mostly. Ocassionally, the script won't show my the detailed interfaces on controllers with less than 15 interfaces. I tried to zero out the variables, but I may have missed something. Anyway, here is what I have:

Code:
-----------------------------------------------------------

sub main
'-----------------------------------------------------------
Dim strPrompt
Dim vInterface

crt.Screen.Synchronous = True

'-----------------------------------------------------------
crt.Screen.Send VbCr
strPrompt = trim(crt.Screen.Get(crt.Screen.Rows,0,crt.Screen.Rows,25))
Do
	bCursorMoved = crt.Screen.WaitForCursor(1)
Loop Until bCursorMoved = False
crt.window.caption = strPrompt
'-----------------------------------------------------------

strResults = ""
strResult = ""

crt.Screen.Send "show interface summary " & Chr(13)
do
	strResult = crt.Screen.ReadString("y/n", strPrompt)
	strResults = strResults & strResult 
	If crt.Screen.MatchIndex = 1 Then crt.Screen.Send "y"
	If crt.Screen.MatchIndex = 2 Then Exit Do
loop

vInterface = split(strResults, vbcrlf)
For nIndex = 5 to Ubound(vInterface) - 1
	Select Case trim(left(vInterface(nIndex - 1),30))
		Case ""
		Case "Would you like to display the"
		Case "------------------------------"
		Case "Interface Name"
		Case Else
		crt.Screen.Send "show interface detail " & trim(left(vInterface(nIndex - 1),30)) & vbcr
	End Select
Next	

crt.screen.synchronous = false


End Sub
'===========================================================
Reply With Quote
  #5  
Old 05-16-2013, 01:58 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Monte,

Your question is really related to VBScript rather than SecureCRT, but we do have some experience with VBScript, so we can provide some pointers.

The VBScript Split() function returns a single dimension array. That is the first important point which you seem to have found.

Splitting on a carriage return and a line feed is a great starting point. Once you have that, you may want to consider using regular expressions to parse the data for each interface.

If you don't want to go the regular expression route (I can understand since it is so complex), the solution you are using seems like you are on the right track.

It seems like you could just iterate over the array using the following rather than a case statement:
Code:
vInterface = Split(strResults, vbcrlf)
For Each strInterface In vInterface
    If InStr(strInterface, "interface") Then
        crt.Screen.Send "show interface detail " & Trim(Left(strInterface, 30)) & vbcr
    End If
Next
Another thing to confirm would be whether the remote is actually sending a carriage return followed by a line feed.

Does this help you move forward with your script?

Can you provide more detail about how the script fails?
__________________
--Todd

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

Last edited by rtb; 05-16-2013 at 02:40 PM.
Reply With Quote
  #6  
Old 05-16-2013, 02:25 PM
Monte.Tucker Monte.Tucker is offline
Registered User
 
Join Date: Sep 2005
Location: Phoenix, AZ
Posts: 33
answer

Actually, I'm happy with the results of the code I posted earlier. There are a couple things I will look at fixing. If the screen isn't full, as if I just logged in, no interface details show, but if I just fill the screen it works fine.

It is working so well, I was thinking of trying to 'call' this script from other scripts. I didn't want to just copy the code and include it in other scripts.

Thanks for your help,
Monte
Reply With Quote
  #7  
Old 05-16-2013, 02:40 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi Monte,

I am not a network engineer, but I think I see why my suggestion won't work. I am glad that you have a solution. Please post any other specific questions that might arise.
__________________
--Todd

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

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:36 AM.