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-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,039
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,039
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,039
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, 635 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
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:17 AM.