Vi checkload.sh 创建脚本

#!/bin/sh  
TOP_SYS_LOAD_NUM=20
SYS_LOAD_NUM=`uptime | awk '{print $(NF-2)}' | sed 's/,//'`  
  
echo $(date +"%y-%m-%d") `uptime`  
if [ `echo "$TOP_SYS_LOAD_NUM < $SYS_LOAD_NUM"|bc` -eq 1 ]  
then  
    echo "##" $(date +"%y-%m-%d %H:%M:%S") "pkill httpd" `ps -ef | grep httpd | wc -l`  
    pkill httpd  
    sleep 10  
    for i in 1 2 3  
    do  
        if [ `pgrep httpd | wc -l` -le 0 ]  
        then  
            /usr/local/apache2/bin/apachectl start  
            sleep 30  
            echo "##" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef | grep httpd | wc -l`  
        fi  
    done  
else  
    if [ `pgrep httpd | wc -l` -le 0 ]  
    then  
        /usr/local/apache2/bin/apachectl start  
        sleep 30  
        echo "##" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef | grep httpd | wc -l`  
    fi  
fi  

然后在/etc/crontab里增加定时执行的命令:

*/2 * * * * root /root/checkload.sh >>/root/checkload.log

注意 chmod 755 /root/checkload.sh 设置脚本权限

标签: Linux管理维护

添加新评论