Sie sind auf Seite 1von 10

ExtremeXOS: Creating Simple CLI Scripts

Goal
To create a simple script file using the Extreme Networks version of the VI editor - edit

Prerequisites

Experience with ExtremeXOS CLI commands Completion of the online module ExtremeXOS Scripting Basics

Objectives
At the end of this exercise, you will be able to

Access and view the contents of a script file in ExtremeXOS Create and edit a script file in ExtremeXOS Save changes to a script file in ExtremeXOS

Part Number:120576-00 Rev 01]

Creating and Editing Script Files


To complete this exercise you need to access an Extreme Networks switch. The exercise requires only a single switch. You can do so in one of two ways: 1 Login to one of your own switches 2 Login to a Single Switch from the Extreme Networks Remote Lab Access site: 3 Click on http://www.extremenetworks.com/solutions/Remote-Access.aspx

Download Access Instructions and Sample Commands to Practice (482K PDF) Download PuTTY Follow instructions in access document to access one of the Extreme Networks single switches

You can use any of the following commands to create or edit a file in ExtremeXOS. For this exercise you will use the edit script <filename.xsf> command to create and edit script files. edit script <filename.xsf> edit policy <filename.pol> edit upm profile <upm profilename>

Accessing the ExtremeXOS CLI Editor


The edit script command spawns a VI-like editor to create and edit the named file.

Two Modes for Editing


The edit function operates in one of two modes: command and input.

Input Mode
When you first open a file, you are in the command mode. To write in the file, you must be in the input mode. Use the keyboard arrow keys to position your cursor within the file, then press one of the following keys to enter the input mode:

i - To insert text ahead of the initial cursor position a- To append text after the initial cursor position

Command Mode
To escape the input mode and return to the command mode, press the Esc key. At any time if you are not sure what mode you are in, press the Esc key and you will be in the command mode.

Esc - To escape to the command mode

ExtremeXOS: Creating Simple CLI Scripts

Essential edit Commands


There are numerous additional commands that you can use from the command mode. The following list contains the most commonly used:

i and a - To enter Insert Mode and begin inputting text


i - To insert text ahead of the initial cursor position a- To append text after the initial cursor position

Cursor keys (arrows) - To move the cursor up and down one line (with characters) or right and left one character. You can also use the cursor keys while in input mode. dd - To delete the current line yy - To copy the current line p - To paste the line copied o - To open line below cursor and enter insert mode r - To replace one character under the cursor. Specify count to replace a number of characters (for example, r6 replaces the next 6 characters with the new characters you type) u - undo the last change to the file. Typing u again will re-do the change. x - delete character under the cursor. Count specifies how many characters to delete. The characters will be deleted after the cursor. :s - To save the file :w - To write (save) the file :q - To quit the file if no changes were made :q! - To forcefully quit the file without saving changes :wq - To write and quit the file ZZ - To write and quit the file Esc - Escapes from input to command mode

Practicing with the ExtremeXOS CLI Editor


Practice with the ExtremeXOS CLI editor includes the following activities. 1 Create a new script file 2 Add content to the file 3 Save the file and continue editing 4 Save and close the file 5 Edit the content in the file 6 Remove or delete the file. Follow the steps in the sections below to get experience with the ExtremeXOS CLI editor.

ExtremeXOS: Creating Simple CLI Scripts

Create a New Script File


In this exercise you will create a script (.xsf) file. This script file, when run, creates 24 VLANs. 1 From the command line, create a new file by typing the following command. edit script testscript.xsf You will see the following:
X450a-24t.43 # edit script testscript.xsf ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "testscript.xsf" line 1 of 1 --100%--

NOTE
Status line shows when you begin the insert mode.

Add Content to the File


2 Type i for Insert to begin typing the text of your file. 3 Type the # to indicate a comment, that will not be included in the script but will provide relevant information. # Beginning of script to generate 24 VLANS nd provision the switch for L3 #

ExtremeXOS: Creating Simple CLI Scripts

Save the File and Continue Editing


4 Press the Esc key to escape to the command mode and type :s to save your file. Press Enter and you will see the following appear at the bottom of the file.
---------------------------------------noautoindent flash ignorecase showmatch tabstop=8 [Hit return to continue]

5 Press Enter to continue, then move your cursor to the next line. You might need to type o to open a new line below the cursor to continue. Type the following:
enable cli scripting ena cli-config-logging create log entry CLI_script_started_by_user_$(cli.user)_via_$(cli.session_type) set var count 1 set var tag ($count +1000) config vlan default delete ports all #

NOTE
You can quit editing at any time without saving your changes by pressing Esc to escape to the command mode and typing :q!.

Save and Close the File


6 Press the Esc key to exit to the command mode and type :wq (or ZZ) to save your file and quit your file editing.

Edit the Content


7 Return to the file by typing
edit script testscript.xsf

8 Move the curser to first line to make a correction. Move it until it is on top of the n of nd. Type i for insert mode and insert an a to change nd to and. NOTE
ExtremeXOS edit has no :set option to set preferences. In order to know which mode you are in press the Esc key. If you are not in the command mode you will go into the command mode. If you are already in the command mode, you will see a screen redraw and remain in the command mode.

ExtremeXOS: Creating Simple CLI Scripts

9 Move your cursor to the final # sign and type o to open a new line and return to the insert mode. Continue typing the remainder of the script as show below.
# while ($count <= 24) do create vlan v_$count configure vlan v_$count tag $tag create log entry VLAN_v_$(count)_created_by_$(cli.user)_using_$(cli.session_type)_session configure vlan v_$count add ports 25-26 tagged configure vlan v_$count add port $count tagged configure vlan v_$count ipaddress 10.1.$(count).1/24 enable ipforwarding v_$count configure rip add vlan v_$count # # if (!$match($count, 12)) then create log entry Halfway_done_with_VLAN_script endif # set var count ($count+1) set var tag ($tag+1) endwhile ena rip show vlan create log entry CLI_script_finished dis cli-config-logging # #End of Script #

10 Press Esc to exit to command mode. 11 Type ZZ to save and quit the file.

Edit the Content in the File


Reopen the file with edit script testscript.xsf to review your typing and correct contents if necessary. Use this command should there be any problems in running the script or if you wish to change the script, such as the number of vlans it creates. Use the following editing commands as needed:

r - Followed by a character to replace a character x - To delete a single character under the cursor NOTE

You may choose to use an alternate editor such as Notebook++ which is available from http://notepad-plus.sourceforge.net/uk/site.htm Once your script is written to your satisfaction you can then copy it and paste it into a script file on the switch.

The copy command is the usual ctrl-C. You will need to use the correct paste command for the access software you are using to access the switch. In the case of the Extreme Networks single remote switches used for this exercises you are using PuTTY. The paste command is right click on your mouse to paste into the script file once you have opened it and typed i for insert mode.

ExtremeXOS: Creating Simple CLI Scripts

Test Script Operation


In order to test the operation of your script, type the following command: load script testscript.xsf If there are any errors in your typing, you will see them scroll on the screen. To view the individual messages type CtrlC to kill the script. You can then scroll through the messages to see what lines need to be changed. To see the VLANs you just created with your script, type show vlan and you will see the following:
* X450a-24t.48 # show vlan ------------------------------------------------------------------------------------Name VID Protocol Addr Flags Proto Ports Virtual Active router /Total ------------------------------------------------------------------------------------Default 1 --------------------------------------- ANY 0 /0 VR-Default Mgmt 4095 --------------------------------------- ANY 0 /1 VR-Mgmt v_1 1001 10.1.1.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_10 1010 10.1.10.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_11 1011 10.1.11.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_12 1012 10.1.12.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_13 1013 10.1.13.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_14 1014 10.1.14.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_15 1015 10.1.15.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_16 1016 10.1.16.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_17 1017 10.1.17.1 /24 -f----------------- ANY 0 /3 VR-Default v_18 1018 10.1.18.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_19 1019 10.1.19.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_2 1002 10.1.2.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_20 1020 10.1.20.1 /24 -f----------------- ANY 0 /3 VR-Default v_21 1021 10.1.21.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_22 1022 10.1.22.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_23 1023 10.1.23.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_24 1024 10.1.24.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_4 1004 10.1.4.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_5 1005 10.1.5.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_6 1006 10.1.6.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_7 1007 10.1.7.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_8 1008 10.1.8.1 /24 -f--------r-------- ANY 0 /3 VR-Default v_9 1009 10.1.9.1 /24 -f--------r-------- ANY 0 /3 VR-Default ------------------------------------------------------------------------------------Flags : (C) EAPS Control VLAN, (d) NetLogin Dynamically created VLAN, (D) VLAN Admin Disabled, (E) ESRP Enabled, (f) IP Forwarding Enabled, (F) Learning Disabled, (i) ISIS Enabled, (L) Loopback Enabled, (l) MPLS Enabled, (m) IPmc Forwarding Enabled, (M) Translation Member VLAN or Subscriber VLAN, (n) IP Multinetting Enabled, (N) Network Login VLAN, (o) OSPF Enabled, (O) Flooding Disabled, (p) PIM Enabled, (P) EAPS protected VLAN, (r) RIP Enabled, (R) Sub-VLAN IP Range Configured, (s) Sub-VLAN, (S) Super-VLAN, (t) Translation VLAN or Network VLAN, (T) Member of STP Domain, (V) VPLS Enabled, (v) VRRP Enabled

Total number of VLAN(s) : 26

ExtremeXOS: Creating Simple CLI Scripts

Create a Second Script


Use the edit script <filename.xsf> to create this second script. This script deletes VLANs on the switch. Name this file vlandelete.xsf by typing edit script vlandelete.xsf.
Set var count 1 While ($count <= 24) do delete vlan v_$count Set var count ($count +1) Endwhile

Use the load script vlandelete.xsf command to test this script. Edit the script if necessary.

Full Scripts
The text below each heading includes the full script for each of the above scripts should you wish to copy and paste the scripts into Notebook++ or other editing program.

Create 24 VLANs
# # Beginning of script to generate 24 VLANs and provision the switch for L3 # enable cli scripting ena cli-config-logging create log entry CLI_script_started_by_user_$(cli.user)_via_$(cli.session_type) set var count 1 set var tag ($count +1000) config vlan default delete ports all # # while ($count <= 24) do create vlan v_$count configure vlan v_$count tag $tag create log entry VLAN_v_$(count)_created_by_$(cli.user)_using_$(cli.session_type)_session configure vlan v_$count add ports 25-26 tagged configure vlan v_$count add port $count tagged configure vlan v_$count ipaddress 10.1.$(count).1/24 enable ipforwarding v_$count configure rip add vlan v_$count # if (!$match($count, 12)) then create log entry Halfway_done_with_VLAN_script endif # # set var count ($count+1) set var tag ($tag+1) endwhile ena rip

ExtremeXOS: Creating Simple CLI Scripts

show vlan create log entry CLI_script_finished dis cli-config-logging # # End of Script #

Delete VLANs
Set var count 1 While ($count <= 24) do delete vlan v_$count Set var count ($count +1) Endwhile

Additional Documentation
You can download additional documentation on CLI scripting from these following locations:

The ExtremeXOS Command Reference The ExtremeXOS Concepts Guide


http://www.extremenetworks.com/services/software-userguide.aspx

Extreme Networks EtherNation, Forums, Widget Garage:


http://www.ethernation.net/Default.aspx?tabid=84&forumid=2&scope=threads

ExtremeXOS: Creating Simple CLI Scripts

10

ExtremeXOS: Creating Simple CLI Scripts

Das könnte Ihnen auch gefallen