[20200306]expand格式化輸出.txt

lfree發表於2020-03-06

[20200306]expand格式化輸出.txt

--//以前提到ss輸出太寬,使用column過濾。實際上輸出是不對齊的。
# ss -notp | column -t
State  Recv-Q  Send-Q  Local                 Address:Port         Peer                         Address:Port
ESTAB  0       0       192.168.100.78:1521   192.168.100.78:9988  timer:(keepalive,6.786ms,0)  users:(("tnslsnr",40011,12))
ESTAB  0       0       192.168.100.78:63637  192.168.100.40:1521  users:(("oracle",23221,10))
ESTAB  0       0       192.168.100.78:63636  192.168.100.40:1521  users:(("oracle",41372,12))
ESTAB  0       0       192.168.100.78:9988   192.168.100.78:1521  users:(("oracle",23173,10))

--// Local Address:Port 應該是一個欄位。比較好的方法是使用expand。

# ss -notp | expand
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
ESTAB      0      0            192.168.100.78:1521        192.168.100.78:9988   timer:(keepalive,18sec,0) users:(("tnslsnr",40011,12))
ESTAB      0      0            192.168.100.78:63637       192.168.100.40:1521   users:(("oracle",23221,10))
ESTAB      0      0            192.168.100.78:63636       192.168.100.40:1521   users:(("oracle",41372,12))
ESTAB      0      0            192.168.100.78:9988        192.168.100.78:1521   users:(("oracle",23173,10))

--//這樣就比較好看了。使用column 不用加 -t 引數也能獲得好的輸出效果。

# ss -notp | column
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
ESTAB      0      0            192.168.100.78:1521        192.168.100.78:9988   timer:(keepalive,3.285ms,0) users:(("tnslsnr",40011,12))
ESTAB      0      0            192.168.100.78:63637       192.168.100.40:1521   users:(("oracle",23221,10))
ESTAB      0      0            192.168.100.78:63636       192.168.100.40:1521   users:(("oracle",41372,12))
ESTAB      0      0            192.168.100.78:9988        192.168.100.78:1521   users:(("oracle",23173,10))

--//看看後面users:(("oracle",23173,10))表示什麼?遠端登入資料庫。

SCOTT@78> @ spid
       SID    SERIAL# PROCESS                  SERVER    SPID                     PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- -------------------- ------- ---------- --------------------------------------------------
        30       2279 8012:7276                DEDICATED 40816                     26         65 alter system kill session '30,2279' immediate;

# netstat -ntop 2>/dev/null | egrep "Proto|40816"
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name    Timer
tcp        0      0 192.168.100.78:1521         192.168.98.6:57576          ESTABLISHED 40816/oraclebook    keepalive (22.94/0/0)

# ss -notp | column | egrep "40816|State"
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
ESTAB      0      0            192.168.100.78:1521          192.168.98.6:57576  timer:(keepalive,20sec,0) users:(("oracle",40816,13))

--//users:(("oracle",40816,13)) 第1個引數是程式名oracle。 第2個引數是程式好。第3個表示什麼呢?
--//猜測是socket檔案控制程式碼:
$ ls -l /proc/40816/fd
total 0
lr-x------ 1 oracle oinstall 64 2020-03-06 10:42:20 0 -> /dev/null
l-wx------ 1 oracle oinstall 64 2020-03-06 10:42:20 1 -> /dev/null
lrwx------ 1 oracle oinstall 64 2020-03-06 10:42:20 13 -> socket:[9648757]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
l-wx------ 1 oracle oinstall 64 2020-03-06 10:42:20 2 -> /dev/null
lrwx------ 1 oracle oinstall 64 2020-03-06 10:42:20 256 -> /mnt/ramdisk/book/system01.dbf
lr-x------ 1 oracle oinstall 64 2020-03-06 10:42:20 3 -> /dev/null
lr-x------ 1 oracle oinstall 64 2020-03-06 10:42:20 4 -> /u01/app/oracle/product/11.2.0.4/dbhome_1/rdbms/mesg/oraus.msb
lr-x------ 1 oracle oinstall 64 2020-03-06 10:42:20 5 -> /proc/40816/fd
lr-x------ 1 oracle oinstall 64 2020-03-06 10:42:20 6 -> /dev/zero
--//很奇怪ss命令沒有man文件。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2678798/,如需轉載,請註明出處,否則將追究法律責任。

相關文章