shell监控服务器是否存活
今天公司服务器继续在10月6号统一重启了次,我怀疑是服务商那边的问题,跟他们联系居然说不可能,明明证据都摆在他面前了,居然还给我狡辩,看来要换得服务商了,还好服务器是月付的,为了防止下次服务器被重启,有些脚本无法运行的情况,我找了个脚本来监控服务器存活情况.
脚本内容:
vi check-ping.sh
然后创建serverip.txt
touch /root/serverip.txt #这个文件是放要监控服务器的ip.
再创建pkgloss.txt
touch /tmp/pkgloss.txt #这个文件是放报错信息的.
最后执行脚本
chmod +x /root/soft_shell/check-ping.sh
nohup sh /root/soft_shell/check-ping.sh &
好了,这下就不怕服务器再被莫名重启了.
ps:http://www.kvm.la/546.html
脚本内容:
vi check-ping.sh
#! /bin/bash
N=2
rmail=rocdk@163.com
while :; do
ipfile=/root/serverip.txt
for ip in `cat $ipfile`; do
mailfile=/tmp/pkgloss.txt
pkgloss=`ping -c4 $ip |grep 'transm' |awk -F',' '{print $2}' |awk '{print $1}'`
if [ $pkgloss -lt $N ]; then
echo $ip >$mailfile
ping -c4 $ip |grep 'transm' >>$mailfile
#mail -s "$ip loss packets" $rmail<$mailfile
mutt -s "$ip loss packets" $rmail<$mailfile
fi
done
sleep 120
done 然后创建serverip.txt
touch /root/serverip.txt #这个文件是放要监控服务器的ip.
再创建pkgloss.txt
touch /tmp/pkgloss.txt #这个文件是放报错信息的.
最后执行脚本
chmod +x /root/soft_shell/check-ping.sh
nohup sh /root/soft_shell/check-ping.sh &
好了,这下就不怕服务器再被莫名重启了.
ps:http://www.kvm.la/546.html


评论: