监控服务器是否宕机的脚本:
$ sudo vi ping.sh
按a或i进入编辑模式
#!/bin/bash
Date=`date +%m%d%y`
touch /log/Ping/$Date.log
Server="ming1 ming2 ming3 ming4 ming5"
for Server in $Server
do
Ping=`/bin/ping -c 4 $Server | grep % | awk -F[:" "]+ '{print $6}' | tr -d '%'`
Ping2=`/bin/ping -c 4 $Server | grep % | awk -F[:" "]+ '{print $8}' | tr -d '%'`
if [ $Ping -eq "0" ]
then
echo "$Server is ok" >> /log/Ping/$Date.log
elif [ $Ping2 -eq "100" ]
then
echo "$Server is down" >> /log/Ping/$Date.log
fi
done
/usr/bin/mail -s "Android Server Status" zhi.yang@spreadtrum.com < /log/Ping/$Date.log
按Esc键退出编辑模式
:wq (保存并退出)
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/1533671如需转载请自行联系原作者
yangzhimingg