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 05-01-2013, 10:21 AM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
"Intelligent" Scripting.

I used to writing Rexx Execs under NetView to control my SNA Network. I could issue a specific VTAM command within the Exec, then take the results, parse thru them and make decisions how to proceed based on those results. Rexx had a built-in facility for doing this.

Does VBScript have a way to perform a similar task?

For Instance, I want to be able to write a script that will issue a display command and then perform certain sub-tasks based on the results of that display command.

Has anyone done something like this in VBScript?
Reply With Quote
  #2  
Old 05-01-2013, 10:45 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
VBScript does provide flow control, and a rich library for parsing data, and also provides regular expressions for more complex parsing.

Did you have a more specific question, or maybe an example line of data that you see in SecureCRT and that you're interested in parsing?

If you are looking for general VBScript resources:
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 05-01-2013, 12:35 PM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
Specific Example.

This is one specific example of what I'd like to do via an automated script process...

Alcatel OS6850 switches are "stackable" and a "virtual chassis" can be made up of from 1 to 8 switch modules.

Frequently, when opening TAC cases on issues, I'm asked to provide the switch logs from each module within the stack for analysis. This involves copying the log files from the modules which are NOT the active Chassis Management Module (CMM) to the active CMM so they can be FTP'd off-chassis and sent to Alcatel.

I would like to be able to issue a SHOW STACK TOPOLOGY command and 'intelligently' determine the number of modules in the stack, the ACTIVE CMM and then copy the log files from all other modules to the active CMM.

Here is a sample of a SHOW STACK TOPOLOGY command:

Link A Link A Link B Link B
NI Role State Saved Link A Remote Remote Link B Remote Remote
Slot State NI Port State NI Port
----+-----------+--------+------+-------+-------+-------+-------+-------+-------
1 PRIMARY RUNNING 1 UP 2 StackB UP 4 StackA
2 SECONDARY RUNNING 2 UP 3 StackB UP 1 StackA
3 IDLE RUNNING 3 UP 4 StackB UP 2 StackA
4 IDLE RUNNING 4 UP 1 StackB UP 3 StackA

In this example, Module 1 is the active CMM (PRIMARY), module 2 is the backup CMM (SECONDARY) and modules 3 and 4 are not CMM's.

In this case, I would want to copy the logs from modules 2, 3, and 4 to module 1 using commands like this:

rcp 2:/flash/swlog1.log /flash/M2_swlog1.log
rcp 2:/flash/swlog2.log /flash/M2_swlog2.log
rcp 3:/flash/swlog1.log /flash/M3_swlog1.log
rcp 3:/flash/swlog2.log /flash/M3_swlog2.log
rcp 4:/flash/swlog1.log /flash/M4_swlog1.log
rcp 4:/flash/swlog2.log /flash/M4_swlog2.log

This is all pretty straightforward and I have done this via script before when things look like they do above... but The kicker is that the ACTIVE (PRI) CMM could be any member of the stack.

In this example, if Module 3 were PRIMARY, then I would need to copy the logs from Modules 1, 2 and 4. Hence, my desire to parse the TOPOLOGY display, interpret the results and take the appropriate actions based on those results.

There are multiple other things I'd like to be able to do across a stacked switch (checking directory contents and reporting back if there are CRASH files present, etc).

I hope this info helps clarify my goal...

I want to issue some command, interpret the results and take specific sets of actions... If "A" do this, if "B" do that, if "C" do something entirely different...

Thanks!!!
Reply With Quote
  #4  
Old 05-01-2013, 12:59 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Quote:
I hope this info helps clarify my goal...
Yes, thanks!

To make this scriptable I believe you'll need to identify a pattern. Often it's possible to:
  1. Wait for a command prompt
  2. Issue a command
  3. Get all of the command results until the command prompt appears again
Do you have a consistent command prompt on the device, such as '#'?

Will you be able to issue a command, and gather data until some known text marker, such as the command prompt?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #5  
Old 05-16-2013, 08:17 AM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
Command Prompt

Yes; the devices will have a sonsistent element of the command prompt (in this specific case "-> " for my Alcatel switches...
Reply With Quote
  #6  
Old 05-16-2013, 09:40 AM
gunslingor gunslingor is offline
Registered User
 
Join Date: May 2013
Posts: 27
Quote:
Originally Posted by George_Fee View Post
This is one specific example of what I'd like to do via an automated script process...

Alcatel OS6850 switches are "stackable" and a "virtual chassis" can be made up of from 1 to 8 switch modules.

Frequently, when opening TAC cases on issues, I'm asked to provide the switch logs from each module within the stack for analysis. This involves copying the log files from the modules which are NOT the active Chassis Management Module (CMM) to the active CMM so they can be FTP'd off-chassis and sent to Alcatel.

I would like to be able to issue a SHOW STACK TOPOLOGY command and 'intelligently' determine the number of modules in the stack, the ACTIVE CMM and then copy the log files from all other modules to the active CMM.

Here is a sample of a SHOW STACK TOPOLOGY command:

Link A Link A Link B Link B
NI Role State Saved Link A Remote Remote Link B Remote Remote
Slot State NI Port State NI Port
----+-----------+--------+------+-------+-------+-------+-------+-------+-------
1 PRIMARY RUNNING 1 UP 2 StackB UP 4 StackA
2 SECONDARY RUNNING 2 UP 3 StackB UP 1 StackA
3 IDLE RUNNING 3 UP 4 StackB UP 2 StackA
4 IDLE RUNNING 4 UP 1 StackB UP 3 StackA

In this example, Module 1 is the active CMM (PRIMARY), module 2 is the backup CMM (SECONDARY) and modules 3 and 4 are not CMM's.

In this case, I would want to copy the logs from modules 2, 3, and 4 to module 1 using commands like this:

rcp 2:/flash/swlog1.log /flash/M2_swlog1.log
rcp 2:/flash/swlog2.log /flash/M2_swlog2.log
rcp 3:/flash/swlog1.log /flash/M3_swlog1.log
rcp 3:/flash/swlog2.log /flash/M3_swlog2.log
rcp 4:/flash/swlog1.log /flash/M4_swlog1.log
rcp 4:/flash/swlog2.log /flash/M4_swlog2.log

This is all pretty straightforward and I have done this via script before when things look like they do above... but The kicker is that the ACTIVE (PRI) CMM could be any member of the stack.

In this example, if Module 3 were PRIMARY, then I would need to copy the logs from Modules 1, 2 and 4. Hence, my desire to parse the TOPOLOGY display, interpret the results and take the appropriate actions based on those results.

There are multiple other things I'd like to be able to do across a stacked switch (checking directory contents and reporting back if there are CRASH files present, etc).

I hope this info helps clarify my goal...

I want to issue some command, interpret the results and take specific sets of actions... If "A" do this, if "B" do that, if "C" do something entirely different...

Thanks!!!
Sounds to me like it would be possible. Let me get this straight, you run that command and the output is shown as you show above; however, the "primary" and "secondary" device changes often and you only want to grab the logs from everything that is NOT the primary device?

Sounds straight forward. I'd:
1. issue the command and assign the output back to a string variable using readstring().
2. then use the instr, instrrev and mid functions to reduce this down so that you only have the following in the string variable:
Quote:
1 PRIMARY RUNNING 1 UP 2 StackB UP 4 StackA
2 SECONDARY RUNNING 2 UP 3 StackB UP 1 StackA
3 IDLE RUNNING 3 UP 4 StackB UP 2 StackA
4 IDLE RUNNING 4 UP 1 StackB UP 3 StackA
3. maybe then convert this to an array, where each row above is an element (using the same functions above).
4. Search each element in the array for the word "Primary", when found delete the element from the array and shift the array around so that there aren't blank/Null values in the elements.
5. Then it looks like you can use an instr and search for the first occurrence of a number (I think # is the wild card, but verify) for each element in an array. Find once you know the start/end locations of the 1/2/3/4/etc, you use the mid function and possibly a new array (or the same array) to assign just these first numbers... so now you have an array of numbers, excluding the number associated with the primary device.
6. then you can run your commands... something like this within the context of the secureCRT objects:
Quote:
For each n in the array do this
"rcp" & array(n) & ":/flash/swlog1.log /flash/M" & array(n) & "_swlog1.log
"rcp" & array(n) & ":/flash/swlog2.log /flash/M" & array(n) & "_swlog2.log
Make sense? does it help?
Reply With Quote
  #7  
Old 05-17-2013, 01:18 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
George_Fee,

There's a similar task/conversation happening here on our forums.

I started a little bit of example code to see if I could demonstrate one way to parse the output you showed:
Quote:
1 PRIMARY RUNNING 1 UP 2 StackB UP 4 StackA
2 SECONDARY RUNNING 2 UP 3 StackB UP 1 StackA
3 IDLE RUNNING 3 UP 4 StackB UP 2 StackA
4 IDLE RUNNING 4 UP 1 StackB UP 3 StackA
After the parsing was done, the script seemed like it might be close to what you were asking for, so I'm posting it below and have attached it as well (always looks better in your favorite editor).
Code:
#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True


Sub Main

        ' Wait for the prompt before kickoff
	strPrompt = "-->"
	crt.Screen.WaitForString strPrompt 
	
	' Send the command
         strCommand = "SHOW STACK TOPOLOGY"
	crt.Screen.Send strCommand & vbcr
	
	' This next line in which we wait for the command and carriage return
	' is here to swallow the command so ReadString() doesn't see it
	crt.Screen.WaitForString strCommand & vbcr  

	' Read the command response
	'
	' Note: ReadString reads all data since the last 
	' WaitForString, WaitForStrings, or ReadString.  
	' See http://www.vandyke.com/support/tips/scripting/scripting_essentials.pdf
	' especially chapter 4 for more info about reading data 
	' from remote machines.
	'
	' Sample command response:
	'	1 PRIMARY     RUNNING    1    UP          2   StackB  UP          4   StackA
	'   2 SECONDARY   RUNNING    2    UP          3   StackB  UP          1   StackA
	'	3 IDLE        RUNNING    3    UP          4   StackB  UP          2   StackA 
	'	4 IDLE        RUNNING    4    UP          1   StackB  UP          3   StackA 
	strResult = Trim(crt.Screen.ReadString(strPrompt))
	
	vLines = Split(strResult, vbcr, -1, 1)
	For i=0 To UBound(vLines)-1
	    ' Let's see the line we're working with
		'crt.Dialog.MessageBox vLines(i) 
		
		' Let's split the line further so that we can get at 
		' module number, status (RUNNING, UP, StackA/B, etc.)
		' and anything else we care to use
		vLinesElements = Split(vLines(i), " ", -1, 1)
		nModule  = Trim(vLinesElements(0))
		
		nMagicModuleNumberToSkip = 1
		If nModule <> nMagicModuleNumberToSkip Then 
			strSrc1 = "/flash/swlog1.log"
			strSrc2 = "/flash/swlog2.log"
			
			strDst1 = "/flash/" & "M" & nModule & "_swlog1.log"
			strDst2 = "/flash/" & "M" & nModule & "_swlog2.log"
			
			strRcpCommand1 = strSrc1 & " " & strDst1
			strRcpCommand2 = strSrc2 & " " & strDst2	
			
			crt.Dialog.MessageBox strRcpCommand1 
			crt.Dialog.MessageBox strRcpCommand2
		End If
		
		' Do more work, send command, etc..
		' .
		' .
		' .
		
	Next
End Sub
Attached Files
File Type: txt ExampleAlcatelStackTopologyParser.vbs.txt (2.1 KB, 295 views)
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]

Last edited by miked; 05-17-2013 at 01:35 PM. Reason: Replacing "./shownetworktopology" with SHOW STACK TOPOLOGY
Reply With Quote
  #8  
Old 12-23-2013, 04:24 PM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
Long Overdue Response.

Hi Team!

I finally had a free minute to get back to this issue... I was able to use part of the example code last provided, but had to tweak things a bit to get a more desirable result...

Like changing "For i=0 To UBound(vLines)-1" to "For i=4 To UBound(vLines)-2" to ignore the headings and insignificant trailing lines.

Also, the parsing of the actual display lines was a little more "hinkey" than I would have hoped... Your example had:

vLinesElements = Split(vLines(i), " ", -1, 1)
nModule = Trim(vLinesElements(0))

But the parser actually considered the individual spaces to be significant, so I had to code:

vLinesElements = Split(vLines(i), " ", -1, 1)
nModule = Trim(vLinesElements(3))

to actually get the module number as 0, 1 and 2 were the three blanks before the module number.

I was also able to figure out how to isolate the PRIMARY and pull the logs from all other modules (even when module 1 was not the active PRIMARY).

I've started looking at taking the info from another command and parsing it out, but the way the parser handles blanks means that as my data changes, so does the element number I have to pull to get what I want...

For example, in this excerpt from a display

1/9 enable up none ""
1/10 enable down none ""

1/9 and 1/10 are element 1 (there is one blank before each).
1/9 has four blanks between the '9' and 'enable', but 1/10 has only 3 blanks between the '10' and 'enable'...

Is there a way to easily split the lines apart based on character position rather than on some variable number of blank spaces?

I'm actually interested in the interface 1/9 and 1/10, etc, and the actual status up/down, the rest of the display is junk.

I also need to parse thru another command display to determine the VLAN assotiation and then I need to marry the two results into a single output which shows me the interface number, status and VLAN association...

Of course, Cisco provides all of the needed info on the "show interface status" command, but my partners with Alcatel did not create a command that shows status and VLAN in the same display...
Reply With Quote
  #9  
Old 12-23-2013, 04:31 PM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
One More Thing...

I assume I should be able to somehow "tableize" the 96 lines of interface displays including the interface numbers (1/1 thru 1/48 and 2/1 thru 2/48) and the interface status (up or down) and then update the VLAN association from the second display into the same table/array so that I then dump out a CSV file containing the combined results from the table...

Or, that's what I HOPE to be able to do...

Thanks again!
Reply With Quote
  #10  
Old 12-24-2013, 09:07 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,293
Hello George_Fee,

I would like to address your first post from yesterday *first*...

Please note that any examples we provide are just that ... examples. It's doubtful we can replicate a user's exact environment or account for all variables that might occur, so editing and tweaking is likely always going to be necessary.

It sounds like you have had good success in accomplishing your goal.

Is this the only part that remains?

Quote:
Is there a way to easily split the lines apart based on character position rather than on some variable number of blank spaces?
If so, you will want to read up on the Left(), Right() and Mid() functions available in VBScript. Or, you may need to use a regular expression to get at the desired data.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 12-24-2013, 09:47 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,293
Hi George_Fee,

Regarding the second post, I am not quite sure what you are asking (or if you *do* have a question).

If you want to store the information in Excel, we do have some script examples for working with Excel here.

The main sticky that provides the link to the specific script examples is at this URL:

http://forums.vandyke.com/showthread.php?t=10365
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #12  
Old 12-24-2013, 11:58 AM
George_Fee's Avatar
George_Fee George_Fee is offline
Registered User
 
Join Date: Feb 2012
Location: Plano, TX
Posts: 18
Happy Holidaze!

Brenda,

Thanks for the hint... It looks like I am able to chop the string into pieces using MID to get to what I want... now I have one more quandry...

I'm using a loop to step through the lines of the display and there are some lines I do not care to keep... when the interface is 0/nn I don't want to keep the entry.

I've parsed the value down to the point I can say if nnn = "0" then... but that's where I'm stumped. I want the code to just skip to the next line in the input buffer (i.e. jump right to "next" without executing any of the statements between the IF and the NEXT.

I've attached a sample of the display I'm chopping to bits and a sample of the section of code doing the chopping...

I feel like I'm really close now. Thanks so much for your help!
Attached Files
File Type: txt Samp1.txt (5.3 KB, 274 views)
File Type: txt Samp2.txt (548 Bytes, 222 views)
Reply With Quote
  #13  
Old 12-26-2013, 09:07 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,293
Hi George_Fee,

If I correctly understand your objective, you probably want to set up an If statement that causes the execution of the remaining code statements only if the result is not "0".

For example:

Code:
For i=135 To UBound(vLines)-2

    strTST00 = vLines(i)

    strTST77 = len(strTST00)

    strTST01 = Mid(strTST00,5,2)

    strTST02 = Mid(strTST00,11,4)

    strTST66 = Mid(strTST02,1,1)
    If strTST66 <> "0" Then 
        strTST03 = Mid(strTST00,18,7)
        strTST99 = strTST77 & " | " & strTST66  & " | " & strTST01 & " | " & strTST02 & " | " & strTST03
        crt.Dialog.Messagebox strTST99
    End If 
    
next
__________________
Thanks,
--Brenda

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 06:52 PM.