#!/bin/sh # crontab usage: */2 * * * * /home/http_restart.sh >> /backup/restart_apache.log MIN_RAM=3200 FREE_RAM=`free -m| grep Mem|awk ‘{print $4}‘` echo $(date +"%y-%m-%d") `uptime` if [ `echo "$FREE_RAM < $MIN_RAM"|bc` -eq 1 ] then echo "#0#" $(date +"%y-%m-%d %H:%M:%S") "pkill httpd" `ps -ef | grep httpd | wc -l` /etc/init.d/httpd stop sleep 5 pkill httpd sleep 5 for i in 1 2 3 do if [ `pgrep httpd | wc -l` -le 0 ] then /etc/init.d/httpd start sleep 10 echo "#1#" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef | grep httpd | wc -l` fi done fi
时间: 2024-10-25 22:43:56