bash shell批量判斷主機的死活

#!/bin/bash
echo "please input begin num: "
read begin_num


echo  "please input end num: "
read end_num


echo  "Test is begining...."


for i in `seq $begin_num $end_num`
do


export host=172.16.1.$i

c=`ping -c 10 $host |grep 'packet'|gawk -F "," '{print $3}'|gawk '{print $1}'|sed s/\%//`
    echo
    echo "$c% packet loss for $host"


if [ $c -lt 10 ];then
    echo "The host $host is lived "


else
    if [ $c -lt 50  ];then
    echo  "The host $host is edge of life and death "

   else
    echo  "The host $host is die"
    fi


fi


done


########################################################################

image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章