Network×Network目次

スポンサードリンク

Fortigate grep

今回はFortigateのgrepコマンドについてのメモ。
FortigateでCLIからshow full-configurationを叩くと
結構膨大な量のログが画面上に流れることになる。

そこでポートwan1の情報を局所的に突然見たくなったとしよう。
ここで役に立つのがgrepコマンドである。
-------------------------------------------------------------------
Fortigate-test# show full-configuration | grep "wan1"
edit "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set interface "wan1"
set dstintf "wan1"
set device "wan1"
set device "wan1"
set device "wan1"
set device "wan1"
set device "wan1"
set device "wan1"
set device "wan1"
Fortigate-test#
-------------------------------------------------------------------

けど局所的な"wan1"だけを表示しても正直意味がわかりませんね。
そこで役立つのがgrepのオプションとなります。
オプションを表示させるために一度わざと構文を間違えます。

-------------------------------------------------------------------
Fortigate-test# show full-configuration | grep "wan1" -z
grep: invalid option -- 'z'
Usage: grep [-invfcABC] PATTERN
Options:
-i Ignore case distinctions
-n Print line number with output lines
-v Select non-matching lines
-f Print fortinet config context
-c Only print count of matching lines
-A Print NUM lines of trailing context
-B Print NUM lines of leading context
-C Print NUM lines of output context
Fortigate-test#
-------------------------------------------------------------------

日本語に直すと以下のようになりますでしょうか。
-i 大文字小文字の区別をしない
-n 指定文字の行数を表示する
-v 指定文字以外を表示する
-f 指定文字を含む行と階層をすべて表示する
-c 指定文字を含む行数を表示する
-A 指定文字を含む下※何行を表示する 
-B 指定文字を含む上※何行を表示する
-C 指定文字を含む上下※何行を表示する
  ※何=数字を指定

オプションを使ってコマンドを叩いてみましょう。
ここからは大文字小文字が含まれるget system statusをgrepしていきます。

◆ -i 大文字小文字の区別をしない
-------------------------------------------------------------------
Fortigate-test# get system status | grep bios

Fortigate-test# get system status | grep bios -i
BIOS version: 05000006
-------------------------------------------------------------------
◆ -n 指定文字の行数を表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -n
11:BIOS version: 05000006
-------------------------------------------------------------------
◆ -v 指定文字以外を表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -v
Version: FortiGate-100D v5.6.3,build1547,171204 (GA)
Virus-DB: 1.00123(2015-12-11 13:18)
Extended DB: 1.00000(2012-10-17 15:46)
IPS-DB: 6.00741(2015-12-01 02:30)
IPS-ETDB: 0.00000(2001-01-01 00:00)
APP-DB: 15.00793(2020-03-10 01:44)
INDUSTRIAL-DB: 6.00741(2015-12-01 02:30)
Serial-Number: FG
IPS Malicious URL Database: 2.00578(2020-03-10 07:20)
Botnet DB: 1.00000(2012-05-28 22:51)
System Part-Number: P11510-
Log hard disk: Available
Hostname: Fortigate-test
Operation Mode: NAT
Current virtual domain: root
Max number of virtual domains: 10
Virtual domains status: 1 in NAT mode, 0 in TP mode
Virtual domain configuration: disable
FIPS-CC mode: disable
Current HA mode: standalone
Branch point: 1547
Release Version Information: GA
FortiOS x86-64: Yes
System time: Thu Sep 28 20:58:38 2023
-------------------------------------------------------------------
◆ -f 指定文字を含む行と階層をすべて表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -f
BIOS version: 05000006 <---
-------------------------------------------------------------------
◆ -c 指定文字を含む行数を表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -c
1
-------------------------------------------------------------------
◆ -A 指定文字を含む下何行を表示する 
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -A 3
BIOS version: 05000006
System Part-Number: P11510-08
Log hard disk: Available
Hostname: Fortigate-test
-------------------------------------------------------------------
◆ -B 指定文字を含む上※何行を表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -B 4
INDUSTRIAL-DB: 6.00741(2015-12-01 02:30)
Serial-Number: FG10
IPS Malicious URL Database: 2.00578(2020-03-10 07:20)
Botnet DB: 1.00000(2012-05-28 22:51)
BIOS version: 05000006
-------------------------------------------------------------------
◆ -C 指定文字を含む上下※何行を表示する
-------------------------------------------------------------------
Fortigate-test# get system status | grep BIOS -C 2
IPS Malicious URL Database: 2.00578(2020-03-10 07:20)
Botnet DB: 1.00000(2012-05-28 22:51)
BIOS version: 05000006
System Part-Number: P11510-
Log hard disk: Available
-------------------------------------------------------------------

grepコマンドのオプションはもちろん重ねることもできます。
絞りたい文字列がはっきりしている場合はかなり便利ですね。
TOP OF THE NETWORK×NETWORK
NETWORK×NETWORK
posted by シスコ | Comment(0) | TrackBack(0) | Fortigate | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:


この記事へのトラックバック