checkhoststatus-检查主机是否存活脚本

#/bin/bash
#2012-04-28 orcs

DATE=$(date +%Y-%m-%d_%H:%M)
[ -d /root/down.log ] | touch /root/down.log
[ -d /root/ps.log ] | touch /root/ps.log
for n in 1 81 80 188 199 49 42 46 41 19 15 43 49;
do
host=192.168.0.$n
ping -c2 $host &>/dev/null
if [ $? = 0 ];then
echo "$host is UP"> /dev/null
else
echo "主机$host于$DATE无法ping通,请及时查看该主机状态" >> /root/down.log
echo "检查主机$host于${DATE}状态异常" >> /root/hoststatus.log
sleep 2
mail -s "pinla servers status" < /root/down.l
og
fi
done
sleep 1
ps aux |grep "sh checkhoststatus.sh"|grep -v grep|awk '{print $2}' > /root/ps.log
ps aux |grep "mail -s 服务器状态 -v grep|awk '{print $2}' >> /root/ps.log
for PS in $(cat /root/ps.log);
do
kill -9 $PS
done
rm -rf /root/down.log /root/ps.log

你可能感兴趣的:(检查,主机,checkhoststatus)