29.04.2019 Views

OS6860(E)_AOS_8.1.1.R01_Switch_Management_Guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Web Services, CLI Scripting, and OpenFlow<br />

CLI Scripting<br />

The $_ represents the most recently used parameter. For instance, the following would result in VLAN 5<br />

being created and then deleted:<br />

vlan 5<br />

no vlan $_<br />

Adding user interaction<br />

To enhance a function even further user interaction can be added. As an example, to have the function<br />

prompt the user for information the read command can be used to read user input as in the example<br />

below:<br />

function myvlans()<br />

{<br />

echo -n "Enter VLAN id: "<br />

read vlanid<br />

if [ "$vlanid" -eq "" ]; do<br />

echo "No VLAN ID entered..."<br />

return 1<br />

fi<br />

vlan $vlanid<br />

}<br />

CLI Tools<br />

awk<br />

Shell-based scripting is only one aspect of the programmability of the <strong>AOS</strong> CLI. Specialized tools such as<br />

grep can also be invoked to refine the behavior of CLI commands. Additionally, awk offers a powerful<br />

syntax for advanced users.<br />

The following is a list of some of the more common tools available in <strong>AOS</strong>:<br />

• Page/search in current output/file: more, less<br />

• Search/Filter files, output on strings, regular expressions: egrep, fgrep, grep<br />

• Filter file/output: cat, head, tail<br />

• Input parser (Can be used in conjunction with other commands such as 'find' or 'cat'): sed<br />

• Count words/line/characters in file/current output: wc<br />

• Evaluate arbitrary expressions (Bash built-in evaluation engine): expr<br />

• Search for files: "find (based on name/wildcard, file type, access date, etc.). Combined with xargs or<br />

using built-in -exec can be used in conjunction with grep, etc.<br />

• Compare files: cmp, diff<br />

As mentioned earlier, awk is scripting language in its own right. Here is a sample awk script that can be<br />

used to filter output based on current grouping. The show ip routes command produces the following<br />

output:<br />

+ = Equal cost multipath routes? Total 25886 routes<br />

Omni<strong>Switch</strong> <strong>AOS</strong> Release 8 <strong>Switch</strong> <strong>Management</strong> <strong>Guide</strong> May 2014 page 10-23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!