em
2013-10-23
01:16 PM
- última edição em
2020-04-24
04:16 PM
por
shokada
このドキュメントは show コマンドの出力フィルターについて説明を行っています。
show コマンドには "|"(パイプ)を使用する事によって、出力結果を整形する事が可能です。
Cisco NX-OS は Cisco IOS よりもオプションが増え,より多様な出力が可能となっています。
NX-OS では以下のようなフィルターオプションが利用できます。なお、Nexus 7000とその他の Nexus シリーズでは使用可能なフィルターが若干異なります。
なお、これらのフィルターオプションで Linxu の shell コマンド由来のオプションの動作は Linux に準拠しています。
# 以下は Nexus 7000 での出力結果です
switch# show logging logfile | ? cut Print selected parts of lines. 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 head Display first lines human Output in human format last Display last lines 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 sed Stream Editor sort Stream Sorter tr Translate, squeeze, and/or delete characters uniq Discard all but one of successive identical lines 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 end End with the line that matches exclude Exclude lines that match include Include lines that match
よく使われる知っていると便利なフィルターオプションを紹介します。
"terminal length 0" を設定しなくても、ページングを無効にログを出力する事ができます。コンソール接続時に "terminal length" の再設定を忘れるといったミスの予防にもなります。
switch# show running-config | no-more
"head" オプションは、文頭から指定された行数(0-2147483647)分を出力します。
"last" オプションは、文末から指定された行数(0-9999)分を出力します。
表示行数を指定しない場合、共にデフォルトで 10 行を出力します。
また、下記の通り行数の指定方法が "head" オプションと "last" オプションで異なります。
switch# show logging logfile | head lines 3 <----- 行指定は "head lines <num>" 2013 Oct 11 05:18:13 N7K-C %SYSLOG-1-SYSTEM_MSG : Logging logfile (messages) cleared by user 2013 Oct 11 05:18:57 N7K-C %ETHPORT-5-IF_DOWN_NONE: Interface Ethernet2/32 is down (Transceiver Absent) 2013 Oct 11 05:18:57 N7K-C %ETHPORT-5-IF_DOWN_NONE: Interface Ethernet2/31 is down (Transceiver Absent) switch# switch# show logging logfile | last 3 <----- 行指定は "last <num>" 2013 Oct 23 11:23:24 N7K-C %SYSMGR-SLOT3-2-SERVICE_CRASHED: Service "aclqos" (PID 19840) hasn't caught signal 11 (core will be saved). 2013 Oct 23 11:23:34 N7K-C %SYSMGR-SLOT3-4-SYSMGR_CORE_TRUNCATED: Core seems to be truncated on generation. 61760 / 62436 KB. PID: 20184 2013 Oct 23 11:23:34 N7K-C %SYSMGR-SLOT3-2-SERVICE_CRASHED: Service "aclqos" (PID 20184) hasn't caught signal 11 (core will be saved).
"begin" オプションは指定した文字列から出力します。
"end" オプションは指定した文字列まで出力します。
以下の例では、"sh int eth1/1-32, Eth2/1-32" と同等(列タイトル行の出力無し)の出力をフィルターオプションにて出力しています。
switch# show interface brief | begin ^Eth1/1 | end ^Eth2/32 Eth1/1 1 eth trunk up none 10G(S) 11 Eth1/2 1 eth trunk up none 10G(S) 12 (省略) Eth2/31 1 eth trunk up none 10G(S) -- Eth2/32 1 eth trunk down SFP not inserted auto(S) --
"grep" / "egrep" / "include" オプションは指定した文字列(正規表現含む)を含む行のみを出力します。
NX-OS の "include" オプションは "egrep" オプションと同等の動きをします。
"grep" / ”egrep” オプションの違いですが、それぞれ使用可能な正規表現が異なります。
以下の例ではスイッチモードで動作するインターフェースの検索を実施していますが、”|”(選択演算子)の書式が異っているのが分かります。
switch# show interface brief | grep "access\|trunk" Eth2/5 1 eth access down SFP not inserted auto(S) -- Eth2/6 1 eth trunk down SFP not inserted auto(S) -- Eth2/7 1 eth access up none 10G(S) -- Eth2/13 1 eth trunk down SFP not inserted auto(S) -- Eth2/15 1 eth access down SFP not inserted auto(S) -- Eth2/27 1 eth trunk up none 10G(S) -- switch# show interface brief | egrep "access\|trunk" <----- 書式が異なるため出力されない switch# switch# show interface brief | grep "access|trunk" <----- 書式が異なる出力されない switch# show interface brief | egrep "access|trunk" Eth2/5 1 eth access down SFP not inserted auto(S) -- Eth2/6 1 eth trunk down SFP not inserted auto(S) -- Eth2/7 1 eth access up none 10G(S) -- Eth2/13 1 eth trunk down SFP not inserted auto(S) -- Eth2/15 1 eth access down SFP not inserted auto(S) -- Eth2/27 1 eth trunk up none 10G(S) --
"grep" / "egrep" オプションによる出力結果のフィルタリングについてはこちらも参照してください。
"exclude" オプションは指定した文字列を含む行の出力を抑制します。
以下の例では Admin shut されたインターフェース、及び SFP が搭載されていないインターフェースを除外して表示しています。
なお、文字列の指定には正規表現が使用出来ます。
switch# sh int b | exclude Admin|SFP <----- grep 準拠の選択演算子 -------------------------------------------------------------------------------- Port VRF Status IP Address Speed MTU -------------------------------------------------------------------------------- mgmt0 -- up 1.110.10.1 1000 1500 -------------------------------------------------------------------------------- Ethernet VLAN Type Mode Status Reason Speed Port Interface Ch # -------------------------------------------------------------------------------- Eth1/11 -- eth routed down Link not connected auto(S) -- Eth2/1 1 eth access up none 10G(S) -- Eth2/5 1 eth trunk up none 10G(S) --
"section" オプションは指定した文字列を含むサブセクションを表示します。
switch# sh ip route vrf all | section 1.4.16.0 1.4.16.0/26, ubest/mbest: 1/0 *via 1.4.50.227, Vlan51, [1/0], 2y11w, static recursive next hop: 1.4.50.227/32 via 1.4.50.129, Vlan55, [200/0], 2y11w, static recursive next hop: 1.4.50.129/32
"sort" オプションは出力を任意のフィールドをキーとして並び替えを行います。
以下の例では、"dir" コマンドの出力をファイルサイズ順に表示しています。
# "dir" コマンドのデフォルト出力はファイル名順
switch# dir | sort 0 Sep 09 04:12:05 2013 20130909_041205_poap_3342_init.log 236 Jun 20 02:13:46 2013 aaa_cnv.log 362 Jun 20 02:13:46 2013 assoc_mgr_cnv.log 589 May 20 08:10:15 2013 MDS201305200107397660.lic 2534 Aug 12 05:54:55 2013 hoge_20130812.cfg 2701 Sep 02 08:07:46 2013 20130902.cfg 2703 Aug 13 01:27:26 2013 hoge_20130813.cfg(省略) (省略)
Nexus シリーズ:Tips - NX-OS の show コマンドフィルターで使用出来る正規表現について
2013 年 10 月 25 日(初版)
2020 年 04 月 24 日(Update)
検索バーにキーワード、フレーズ、または質問を入力し、お探しのものを見つけましょう
シスコ コミュニティをいち早く使いこなしていただけるよう役立つリンクをまとめました。みなさんのジャーニーがより良いものとなるようお手伝いします
下記より関連するコンテンツにアクセスできます