Whether you’re new to Cisco Nexus switches or have been working with them for years this article will show how to get around the Nexus NX-OS using smart CLI commands and parameters, create your own commands and more. Learn how to filter show command outputs, efficiently use include | begin | exclude search operators, Turn pagination on/off, redirect output to files, run multiple commands in one CLI line, capture specific keywords from show command output, create custom CLI commands using alias, execute scripts, introduction of Python environment in the Nexus NX-OS, executing Python scripts and much more!
By the end of this article we’ll agree there’s no doubt the Cisco NX-OS has several interesting commands and powerful scripting capabilities that can improve and facilitate the day-to-day administration of CISCO Nexus network devices.
While basic knowledge on the Cisco NX-OS, Linux and Python scripting is recommended, it is not mandatory in order to understand the topics covered.
Here’s a list of topics covered:
- NX-OS Command Output Filtering – Search Operators
- Filtering Output From The ‘Show’ Command – ‘Show | grep’
- Turning Off Pagination for Lengthy ‘Show’ Command Outputs - ‘Show | no-more’ Parameter
- Searching & Filtering Output from ‘Show’ Command
- Display Last Lines from the ‘Show’ Command Output – ‘Show | last ’
- Redirecting ‘Show’ Command Output To File and Include Timestamps. ‘Show running-config > backupcfg.$(TIMESTAMP) ‘
- Combining Multiple Search Strings – ‘| Include’ Parameter
- Scripting in Nexus NX-OS – Executing Multiple Commands within a File
- Introducing Python in the Nexus NX-OS – Uploading and Executing Python Scripts
- Nexus NX-OS Hints & Tips
- Nexus NX-OS Tip No.5 – Executing Multiple Commands in One Line
- Nexus NX-OS Tip No.4 – Tracking Recent User Configuration Changes
- Nexus NX-OS Tip No.3 – Creating Your Own NX-OS Alias Commands
- Nexus NX-OS Tip No.2 – Quickly Viewing and Executing Past Commands
- Nexus NX-OS Tip No.1 – Comparing Differences in Running & Startup Configuration
Additional related articles:
- Introduction to Cisco Nexus Switches – Nexus Product Family. Differences Between Nexus NX-OS & Catalyst IOS. Comparing High-End Nexus & Catalyst Switches
- Complete Guide to Nexus Checkpoint & Rollback Feature. Fast Recovery from Nexus Misconfiguration. Nexus 9000, 7000, 5000, 3000
NX-OS Command Output Filtering – Search Operators
The output from NX-OS show commands can be lengthy and that makes it difficult to find the information we are looking for. The Cisco NX-OS software provides the means to search and filter the output to assist in locating the information we are after.
Experienced Cisco users will surely be familiar with the IOS (Catalyst) include | begin | exclude search operators which are also offered in the Nexus NX-OS (see below). The NX-OS offers additional searching and filtering options, which follow a pipe character (|) at the end of the show command. This provides amazing flexibility and helps make administration of any Nexus device a great experience. The most “Linux-like” useful options are displayed below:
N5k-UP# show interface brief | ?
<…>
diff Show difference between current and previous invocation (creates temp files: remove them with 'diff-clean' command and dont use it on commands with big outputs, like 'show tech'!)
egrep Egrep - print lines matching a pattern
grep Grep - print lines matching a pattern
less Filter for paging
no-more Turn-off pagination for command output
section Show lines that include the pattern as well as the subsequent lines that are more indented than matching line
sort Stream Sorter
source Run a script (python, tcl,...) from bootflash:scripts
vsh The shell that understands cli command
wc Count words, lines, characters
xml Output in xml format (according to .xsd definitions)
begin Begin with the line that matches
count Count number of lines
exclude Exclude lines that match
include Include lines that match