對於tnsping的連線超時的功能補充(二)(r9筆記第22天)
阿新 • • 發佈:2022-05-04
對於tnsping的一些小問題,自己也想了些辦法來補充,最後發現使用nc是一個不錯的選擇。可以參考 對於tnsping的連線超時的功能補充
主要思想如下:
如果網路是通的,那麼會顯示succeeded,否則會有一些錯誤資訊
# nc -w 2 -v 10.11.65.111 22|grep succ
Connection to 10.11.65.111 22 port [tcp/ssh] succeeded!
# nc -w 2 -v 10.11.65.191 22|grep succ
nc: connect to 10.11.65.191 port 22 (tcp) timed out: Operation now in progress
test1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.2.129)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = peak)
)
)
test2=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.64.161)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = accdb0)(server=dedicated)))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.55.31)(PORT = 1523))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.133.128)(PORT = 1529))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.133.71)(PORT = 1528))
grep -i 'TCP|HOST|PORT' tnsnames.ora|grep -v #|awk -FHOST '{print $2}'|sed 's/PORT//g'|awk -F= '{print $2 $3}'|sed -e 's/CONNECT_DATA//g' -e 's/(//g' -e 's/)//g'|awk '{print "nc -w 2 -v "$1" "$2"|grep succ"}'|sort|uniq> a.sh
輸出的檔案格式就會是下面的形式:
nc -w 2 -v 192.168.97.17 1521|grep succ
nc -w 2 -v 192.168.97.60 1532|grep succ
nc -w 2 -v 192.168.97.83 1522|grep succ
nc -w 2 -v 210.245.20.28 1521|grep succ
nc -w 2 -v bak.test.com 1521|grep succ
直接執行生成的指令碼即可。在一些耦合性高的環境中,這種方式就非常有效了,那些成功,哪些失敗,一目瞭然。我們也可以只分析哪些失敗的。
Connection to 10.11.133.15 1523 port [tcp/cichild-lm] succeeded!
Connection to 10.11.133.16 1528 port [tcp/mciautoreg] succeeded!
nc: connect to 10.11.133.163 port 1521 (tcp) timed out: Operation now in progress
Connection to 10.11.65.23 1528 port [tcp/mciautoreg] succeeded!
nc: connect to 192.168.1.41 port 1523 (tcp) timed out: Operation now in progress
nc: connect to 210.245.20.28 port 1521 (tcp) failed: Network is unreachable
nc: connect to bak.test.com port 1521 (tcp) timed out: Operation now in progress
這種方式就會大大提高我們分析問題的效率。