監控埠
方法
測驗埠是不是有回應
用telnet 協議
-
先判斷依賴telnet是不是存在
-
用telnet訪問埠,把檔案輸出寫到臨時檔案
-
然后 判斷檔案有沒有^]
-
最后洗掉臨時檔案
#!/bin/bash
port_status(){
temp_file=`mktemp port_status.XXX`
[ ! -x /usr/bin/telnet ] && echo "telnet: not found command" && exit 1
(telnet $1 $2 << EOF
quit
EOF
) &>$temp_file
# 判斷檔案中是否存在 ^]
if egrep "\^]" $temp_file &>/dev/null;then
echo -e "$1 $2 is \033[32m open \033[0m"
else
echo -e "$1 $2 is \033[31m close \033[0m"
fi
# 洗掉臨時檔案
rm -f $temp_file
}
port_status $1 $2
效果

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/260341.html
標籤:其他
上一篇:Nginx-1.18 +Https(免費版) + openresty-1.17.8.2 + LVS+keepalived實戰(Centos7.8)
下一篇:Jenkins如何部署
