MLNX-OS CLI Filters, watch and Link Diagnostics Commands - 夜莺博客

MLNX-OS CLI Filters, watch and Link Diagnostics Commands

MLNX-OS has the most Linux-flavoured CLI of the major data centre network operating systems, and two features make it genuinely faster to troubleshoot than IOS or Junos: pipeline operators that filter, watch and reformat any show command, and per-port link diagnostics that report physical-layer state with numeric status codes. This article collects the output-processing tricks from the official MLNX-OS user manual and shows how to use them on a real switch.

CLI Modes and Completion

The MLNX-OS CLI uses Standard mode (switch>), enable mode (switch#) and configuration mode (switch (config) #). Commands support tab completion and shortened forms — en for enable, cli cl for cli clear-history — and pressing tab twice after a letter lists all possible completions. Error responses begin with a percent sign, so % at the start of a line means the command was rejected.

Filtering Show Output with include and exclude

Any show command can be piped to a filter with | include or | exclude plus an extended regular expression, with optional case-insensitivity and context lines:

switch (config) # show interfaces ethernet | include "up" ignore-case
switch (config) # show interfaces ethernet 1/1 | exclude "0 packets"
switch (config) # show mac address-table | include "00:02:c9" next 2 prev 2

Multiple filters can be chained, and quoted strings allow spaces inside the pattern. This replaces the IOS habit of piping through grep and gives you context lines in one step.

Monitoring with watch, count and json-print

Watch a counter or state change live without repeated manual pings — ideal during a failover test or a firmware upgrade:

switch (config) # show interfaces counters | watch interval 5
switch (config) # show interfaces counters | watch diff interval 2
switch (config) # show mac address-table dynamic | count
switch (config) # show interfaces ethernet 1/1 | json-print

| watch refreshes the output at the interval you set (2 seconds default) until Ctrl+C; adding diff highlights what changed between refreshes. | count prints only the number of output lines. | json-print returns the state in structured JSON for scripting — note it cannot be combined with include/exclude or watch. See our MLNX-OS getting started guide for the base command set.

Link Diagnostics: Decoding the Status Codes

When a port will not come up, the link-diagnostics commands show exactly what the physical layer sees:

switch (config) # show interfaces ethernet link-diagnostics
Interface            Code  Status
---------------------------------------------------------------
Eth1/1               0     No issue was observed
Eth1/2               1024  Cable unplugged
Eth1/3               2     Auto-Negotiation failure
Eth1/4               1     The port is closed by command

The numeric codes map to physical-layer conditions: 0 means the port is healthy, 1024 reports an unplugged cable, 2 flags an auto-negotiation failure and 1 means the port was administratively closed. This single command separates a dead SFP or cable from a configuration problem in seconds. For the LAG and LACP side of MLNX-OS operations, our MLNX-OS LAG configuration guide picks up where the physical layer leaves off.

原文链接:https://networking-docs.nvidia.com/mlnxosum/3126200lts/command-line-interface-cli