なんこれ
シリアルコンソールの使い方も知らない世間知らずが初めてシリアルコンソールを使ってみて感動した話。
シリアルコンソール???
この形以外にも種類があるので興味があったら調べてみてね。
動作環境
OS | mac |
---|---|
Console | fish, bash |
事前準備
scriptコマンドの最適化をする。
・・・というのもfishだとあまり良くない(プロンプトやTABが出まくる)
実例
実際に事前準備をせずに実行してみよう。
以下の通り、たかだか2行の処理を実施する。
# スクリプト実行
$ script test.log
# ディレクトリ表示
$ ls -la
コンソール上の表示は以下。
わかりやすい。
~/a script test.log 57.7s < 月 2/ 7 15:40:50 2022
Script started, output file is test.log
Darwin kappa3gou 21.1.0 arm64
15:41 up 6 days, 49 mins, 3 users, load averages: 1.98 2.49 2.59
~/a ls -la 月 2/ 7 15:41:16 2022
total 8
drwxr-xr-x 3 maruta staff 96 2 7 15:39 ./
drwxr-xr-x 5 maruta staff 160 2 7 15:39 ../
-rw-r--r-- 1 maruta staff 43 2 7 15:41 test.log
問題のログ出力結果。
Script started on Mon Feb 7 15:41:11 2022
]0;~/a[30m(B[m[38;5;237m⏎(B[m
⏎
[K[38;2;255;215;95mDarwin kappa3gou 21.1.0 arm64
15:41 up 6 days, 49 mins, 3 users, load averages: 1.98 2.49 2.59
(B[m[?2004h]0;~/a[30m(B[m
(B[m[38;2;153;153;153m[48;2;51;51;51m ~/a (B[m[38;2;51;51;51m (B[m[K[61C[38;2;255;215;95m 月 2/ 7 15:41:11 2022(B[m
[78C
[17Cls -la[55C[38;2;255;215;95m 月 2/ 7 15:41:11 2022(B[m
[78C
[23C[55C[38;2;255;215;95m 月 2/ 7 15:41:11 2022(B[m
[78C
[23C]0;~/a[30m(B[m
(B[m[38;2;153;153;153m[48;2;51;51;51m ~/a (B[m[38;2;51;51;51m (B[mls -la[K[55C[38;2;255;215;95m 月 2/ 7 15:41:16 2022(B[m
[78C
[23C[38;2;255;148;0mls[30m(B[m [38;2;255;192;0m-la[55C[30m(B[m[38;2;255;215;95m 月 2/ 7 15:41:16 2022(B[m
[78C
[23C[55C[38;2;255;215;95m 月 2/ 7 15:41:16 2022(B[m
[78C
[23C[55C[38;2;255;215;95m 月 2/ 7 15:41:16 2022(B[m
[78C
[23C
[30m(B[m[?2004l]0;~/a[30m(B[m
total 8
drwxr-xr-x 3 maruta staff 96 2 7 15:39 [36m.[39;49m[0m/
drwxr-xr-x 5 maruta staff 160 2 7 15:39 [36m..[39;49m[0m/
-rw-r--r-- 1 maruta staff 43 2 7 15:41 test.log
[2m⏎(B[m
⏎
[K[?2004h]0;~/a[30m(B[m
(B[m[38;2;153;153;153m[48;2;51;51;51m ~/a (B[m[38;2;51;51;51m (B[m[K[61C[38;2;255;215;95m 月 2/ 7 15:41:17 2022(B[m
地獄。
ということでログを後から整理できるようにプロンプトを書き換えるなどする。
実際に叩くコマンド
# scriptを記録
$ script test.log
# shでターミナルを起動し直す
$ exec sh
# プロンプトをシンプルに
$ PS1="# "
この状態でさっきと同じコマンドを叩いてみる。
Script started on Mon Feb 7 16:05:06 2022
]0;~/a[30m(B[m[38;5;237m⏎(B[m
### 省略
[57C
[17Cexec sh[33C[38;2;255;215;95m 月 2/ 7 16:05:06 2022(B[m
[57C
### 省略
[30m(B[m[?2004l]0;~/a[30m(B[m
[?1034hsh-3.2$ PS1="# "
# ls -la
total 8
drwxr-xr-x 3 maruta staff 96 2 7 16:05 .
drwxr-xr-x 5 maruta staff 160 2 7 15:54 ..
-rw-r--r-- 1 maruta staff 1253 2 7 16:05 test.log
### 以降の処理は全部見やすくなる
# touch file.txt
# echo "test > file.txt
# cat file.txt
test
ということで、シバンを変えてから急にログが見やすくなった。
これ以降はほぼ実行コマンドとログ情報が一致するようになる。
ここまで行ったら以下のコマンドで各端末のコンソールに入ることが可能。
$ screen -l /dev/tty.usbserial-AB6ADZE0
例えばCISCOスイッチならこんな感じ。
System Bootstrap, Version 15.2(3r)XC, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 2012 by cisco Systems, Inc.
Total memory size = 512 MB
*******-** platform with 524288 Kbytes of main memory
Main memory is configured to 32 bit mode
Readonly ROMMON initialized
program load complete, entry point: 0x4000000, size: 0x18c40
program load complete, entry point: 0x4000000, size: 0x18c40
IOS Image Load Test
___________________
Digitally Signed Production Software
program load complete, entry point: 0x4000000, size: 0x3188fd0
Self decompressing the image : ################################################################################################################################################################################################################################################################################################################################################################################################################################################### [OK]
*** No sreloc section
Smart Init is enabled
smart init is sizing iomem
TYPE MEMORY_REQ
Onboard devices &
buffer pools 0x022ECEC0
-----------------------------------------------
TOTAL: 0x022ECEC0
### 中略
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2013 by Cisco Systems, Inc.
### 中略
sw >
以降、各端末に合わせたコマンドが実行可能になる。
?
を入力するとどんなコマンドがあるのかの一覧を確認することができる。
sw>?
Exec commands:
access-enable Create a temporary Access-List entry
access-profile Apply user-profile to interface
clear Reset functions
connect Open a terminal connection
crypto Encryption related commands.
disable Turn off privileged commands
disconnect Disconnect an existing network connection
do-exec Mode-independent "do-exec" prefix support
emm Run a configured Menu System
enable Turn on privileged commands
ethernet Ethernet parameters
exit Exit from the EXEC
help Description of the interactive help system
ips Intrusion Prevention System
lig LISP Internet Groper
lock Lock the terminal
login Log in as a particular user
logout Exit from the EXEC
mrinfo Request neighbor and version information from a multicast
router
mstat Show statistics after multiple multicast traceroutes
--More--
### show のようにコマンドの後ろにつけることで実行可能なオプションが表示される
sw>show ?
aaa Show AAA values
acircuit Access circuit info
adjacency Adjacent nodes
appfw Application Firewall information
arp ARP table
auto Show Automation Template
autoupgrade Show autoupgrade related information
backup Backup status
bfd BFD protocol info
bgp BGP information
calendar Display the hardware calendar
call Show call
call-home Show command for call home
caller Display information about dialup connections
capability Capability Information
cca CCA information
cdapi CDAPI information
cdp CDP information
class-map Show CPL Class Map
clock Display the system clock
cns CNS agents
compress Show compression statistics
--More--
時間指定の再起動やconfig設定・更新処理も実行できるので便利。
終わりのポエム
普段と違うレイヤーで作業してるとそこの世界では初歩中の初歩でも勉強になったりします。
今回はデータセンター業務が降って湧いた時に、そこでプロフェッショナルとして働いてるおじさんに「いやさぁ・・・なんで君こんなんも知らんの?うちの業界じゃ持ってきて無いとか考えられないんだけど😅」とか言われてちょっと恥ずかしい思いをしたけれど、使い方を習うことができたのいい経験になったと思っています。
まぁ、世の中にはこういう便利なものもあるんだぞっていうことを知識として知っておくのはいいことかなと思って書いてみました。
作業効率も断然違うしね。
常識かもしれんけどね。知らなくてごめんね。
追記
@shiracamusさんの指摘を受け修正しました。
コードブロックの言語修正(コンソール画面はconsoleあるいはterminalです。shはシェルスクリプトなのでプロンプトを含まないスクリプトに使います。カラーライズが不要な場合はtextあるいは無指定)
勉強になります🙏