您现在的位置是:网站首页> 编程资料编程资料
监控服务器swap并重启php的Shell脚本_linux shell_
2023-05-26
304人已围观
简介 监控服务器swap并重启php的Shell脚本_linux shell_
折中一下,写个脚本监控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 这一句中间的命令换成你自己的即可
您可能感兴趣的文章:
相关内容
- 通过shell进行数学运算的多种方式_linux shell_
- linux安装php扩展脚本分享_linux shell_
- win下调用putty执行命令脚本分享_linux shell_
- shell实现自动备份mysql、整站数据的两个脚本分享_linux shell_
- bash脚本中if语句的使用方法_linux shell_
- shell脚本监控mysql主从状态_linux shell_
- shell脚本实现的网站日志分析统计(可以统计9种数据)_linux shell_
- shell脚本结合iptables防端口扫描的实现_linux shell_
- 监控php-fpm并自动重启服务的shell脚本_linux shell_
- shell数组操作简明总结_linux shell_
