1. 程式人生 > >bash shell批量判斷主機的死活

bash shell批量判斷主機的死活

#!/bin/bash
echo -e  "\b please input begin num: "
read begin_num


echo -e  "\b please input end num: "
read end_num


echo -e "\b 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