您的位置:首页 > 运维架构 > Shell

bash shell批量判断主机的死活

2019-01-04 17:14 696 查看

#!/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


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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bash shell Linux