#!/bin/bash
#set -x
#crontab
# 8 * * * * ......
function chkserdown()
{
ping -c 1 $1 > /dev/null
if [ $? -eq 0 ];then
if [ -f $2 ];then
rm -f $2
icgname=`basename $2`"_is_ok"
#echo $icgname" is ok"
#这里发送邮件到139手机邮箱
fi
else
if [ ! -f $2 ];then
sleep 5
ping -c 1 $1 > /dev/null
if [ $? -ne 0 ];then
touch $2
icgname=`basename $2`
GW=`echo $1 | sed ‘s/\.[0-9]\{1,3\}$/\.1/‘`
ping -c 1 $GW > /dev/null
if [ $? -eq 0 ];then
icgname=$icgname"_gw_isok_but_host_notok"
else
icgname=$icgname"_gw_and_host_notok"
fi
#这里发送邮件到139手机邮箱
fi
fi
fi
}
MSer="/tmp/MSerdown"
FileSer="/tmp/FileSerdown"
chkserdown "192.168.168.254" $MSer
chkserdown "10.1.1.254" $FileSer简单的shell代码
本文出自 “尽管错,让我错到死!” 博客,请务必保留此出处http://hxw168.blog.51cto.com/8718136/1379795
【shell】使用ping检测机器是否不在线,布布扣,bubuko.com
原文:http://hxw168.blog.51cto.com/8718136/1379795