首页 > 其他 > 详细

【shell】使用ping检测机器是否不在线

时间:2014-03-20 12:53:39      阅读:559      评论:0      收藏:0      [点我收藏+]
#!/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

【shell】使用ping检测机器是否不在线

原文:http://hxw168.blog.51cto.com/8718136/1379795

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!