ExtremeXOS Creating Simple CLI Scripts
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
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>
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.
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
NOTE
Status line shows when you begin the insert mode.
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!.
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.
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.
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.
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
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:
10