linux shell 检测服务是否正常

设置iptables模拟场景
测试设置iptables -I INPUT -p TCP --dport 80 -j DROP
iptables-save
----------------------------------------------------
删除
iptables  -L -n --line-numbers

iptables -D INPUT 1

 

该脚本设置超时为5秒

#!/bin/sh
     servers=`(ps -aux | grep /路径 | grep -v grep |awk '{print $8}')`
     echo "status:" $servers
     if [ -n "$servers" ]; then
        echo "server is working"
        `timeout 5 bash -c 'exec 8<>/dev/tcp/127.0.0.1/80'`
         if [ $? -eq 0 ]; then
            echo "success"
            exec 8<&-
         else 
            echo "need service xxxrestart"
            service xxxrestart
             echo `8<&-`
         fi
       fi
 

我的邮箱:[email protected]   微信:412176346     欢迎大家访问我的网站  www.haozhan6.com

你可能感兴趣的:(linux shell 检测服务是否正常)