shell cpu超90 php-fpm 或nginx重启

#!/bin/sh
# qiyulin to monitor used CPU
record=0
max=90
while true;
do
cpu=$(top -b -n1 | grep '%Cpu(s):' | awk '{print $2}')
if [[ cpu < $max ]];then continue;fi
sleep 10
cpu=$(top -b -n1 | grep '%Cpu(s):' | awk '{print $2}')
if [[ cpu < $max ]];then continue;fi
service php-fpm restart
echo `date +%F" "%H:%M:%S`+" cpu:$cpu%"
sleep 60
done

详解:

写一个循环,截取top命令的的cpu值 超过90则重启

守护进程并写入日志到某文件

 nohup /bin/bash ./checkCpu.sh >> /var/phpfpm_restart.log &
发布了264 篇原创文章 · 获赞 46 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/qq_27229113/article/details/103080826