脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - 监控服务器swap并重启php的Shell脚本

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

2022-12-28 15:32shell教程网 shell

有一台服务器老是交换扇区占满然后失去响应,很烦,因为加载了以前别人写的一个php扩展,效率低,资源占用大,悲剧的是现在还没有可以替换的东西

折中一下,写个脚本监控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 这一句中间的命令换成你自己的即可

延伸 · 阅读

精彩推荐