如何监控服务器swap然后重启php的Shell脚本

本篇内容主要讲解“如何监控服务器swap然后重启php的Shell脚本”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何监控服务器swap然后重启php的Shell脚本”吧!

代码如下:


#!/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 这一句中间的命令换成你自己的即可

到此,相信大家对“如何监控服务器swap然后重启php的Shell脚本”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!