liunx 服务器管理中,有时需要检测主机的存活状态,当主机不多的时候,可以直接使用Ping 命令,当主机很多的时候直接使用ping 命令管理起来就比较麻烦了,使用shell 脚本编写的ping 命令检测主机存活状态,是一个很好的方法。
#!/bin/bashIP=$(cat /root/shell/ip.txt)
status=`echo $?`
Local_ip=`ifconfig | grep "inet" | awk 'NR==3{print $2}'`
for i in $IP
do
if ping $i -c 4 >> /dev/null;then
echo "$i is up,Local_ip $Local_ip to $i network is no problem" >> /root/shell/ip.log
echo "$i is up Local_ip $Local_ip to $i network is no problem"
else
echo "$i is down,Local_ip $Local_ip to $i network is break" >> /root/shell/ip.log
echo "$i is down,Local_ip $Local_ip to $i network is break"
fi
done
本文出自 “sdsca” 博客,请务必保留此出处http://sdsca.blog.51cto.com/10852974/1891234