#!/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 &