#1
|
|||
|
|||
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> 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 |
#2
|
|||
|
|||
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.htmlDo you have a specific question I can help answer? What particular part of your script are you having difficulty writing? |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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 '=========================================================== |
#5
|
|||
|
|||
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 Does this help you move forward with your script? Can you provide more detail about how the script fails? Last edited by rtb; 05-16-2013 at 02:40 PM. |
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
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. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|