Linux telnet、nc、ping監測狀態


    在工作中會遇到網絡出現閃斷丟包的情況,最終影響業務工常使用。可以業務服務器上發起監測。

    1、通過telnet

       echo  -e  "\n" | telnet localhost 22 | grep Connected

       返回結果為$? 為 0 ,證明端口可正常訪問

    2、通過nc

     nc -nz -w 1 192.168.1.3 22    #centos7 以前版本,  在centos7中操作  nc -n  -w 1 192.168.1.3 22 </dev/null  取消了-z,通過重定向可實現.  如果測試UDP 時,加上-u

     返回結果為$? 為 0 ,證明端口可正常訪問

    3、通過ping

      ping -c 1 -w 1  192.168.1.3

     返回結果為$? 為 0 ,證明端口可正常訪問

eg:

#/bin/bash
#check server oracle ip and port

function check_ping(){
    while [ 1 -ne 2 ]
    do
        ping -c 1 -w 1 $1 >> /dev/null
        if [ $? = 0 ];then
            date >> ping_s_y_$1.log
            echo "normal" >> ping_s_y_$1.log
        else
            date >> ping_s_n_$1.log
            echo "abnormal" >> ping_s_n_$1.log
        fi
        sleep 1
   done
}
IP1='10.204.198.13'
IP2='10.204.198.14'
IP3='10.204.14.46'
for IP in $IP1 $IP2 $IP3
do
{
    check_ping $IP
} &
done
wait

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM