监控服务器是否宕机的脚本:
$ 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" [email protected] < /log/Ping/$Date.log
按Esc键退出编辑模式
:wq (保存并退出)
时间: 2024-11-10 11:06:01