User guide
Web Services, CLI Scripting and OpenFlow CLI Scripting
OmniSwitch AOS Release 7 Switch Management Guide March 2015 page 11-23
The $_ represents the most recently used parameter. For instance, the following would result in VLAN 5
being created and then deleted:
vlan 5
no vlan $_
Adding user interaction
To enhance a function even further user interaction can be added. As an example, to have the function
prompt the user for information the read command can be used to read user input as in the example
below:
function myvlans()
{
echo -n "Enter VLAN id: "
read vlanid
if [ "$vlanid" -eq "" ]; do
echo "No VLAN ID entered..."
return 1
fi
vlan $vlanid
}
CLI Tools
Shell-based scripting is only one aspect of the programmability of the AOS CLI. Specialized tools such as
grep can also be invoked to refine the behavior of CLI commands. Additionally, awk offers a powerful
syntax for advanced users.
The following is a list of some of the more common tools available in AOS:
• Page/search in current output/file: more, less
• Search/Filter files, output on strings, regular expressions: egrep, fgrep, grep
• Filter file/output: cat, head, tail
• Input parser (Can be used in conjunction with other commands such as 'find' or 'cat'): sed
• Count words/line/characters in file/current output: wc
• Evaluate arbitrary expressions (Bash built-in evaluation engine): expr
• Search for files: "find (based on name/wildcard, file type, access date, etc.). Combined with xargs or
using built-in -exec can be used in conjunction with grep, etc.
• Compare files: cmp, diff
awk
As mentioned earlier, awk is scripting language in its own right. Here is a sample awk script that can be
used to filter output based on current grouping. The show ip routes command produces the following
output:
+ = Equal cost multipath routes? Total 25886 routes