您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

监控服务器swap并重启php的Shell脚本

来源:互联网 浏览:56次 时间:2023-04-08

折中一下,写个脚本监控swap吧,放在crontab里面,2小时执行一次,世界安静了,再也没有烦人的报警短信了
复制代码 代码如下:
#!/bin/bash
function usage
{
        echo "Usage: $0"
        echo "e.g. $0 1500"
        exit
}
if [ $# -lt 1 ];then
        usage
fi
typeset -i nowSwap limitSwap
limitSwap=$1
nowSwap=$(free -m|grep "Swap"|sed -e "s/\(.*\)\:\(.*\)/\2/g"|awk '{print $2}')
if [ $limitSwap -lt $nowSwap ];then
        while [ 1 ]
        do
                if /etc/init.d/php5-fpm restart|grep -c fail
                then echo "[$(date +%Y/%m/%d0-%H:%M)]restart php failed"
                else
                        echo "[$(date +%Y/%m/%d-%H:%M)]restart php successful!"
                        break
                fi
        done
fi

注:if /etc/init.d/php5-fpm restart|grep -c fail 这一句中间的命令换成你自己的即可

本文从互联网转载,来源地址:www.downzz.com/linux-shell/171506.html,原作者保留一切权利,若侵权或引用不当,请联系茶猫云(cmy.cn)删除。【茶猫云,优质云服务器提供商】