主機負載太高造成死當的解法

#!/bin/sh
# Bash script that checks apache:
# – If server load is higher than 20, kill web server
#
# Script to be ran as cronjob (every 5 minutes)
# */2 * * * * /path/to/httpd_check >> /path/to/httpd_check.log

echo “httpd checker running at ” `date`
check=`uptime | sed ‘s/\./ /g’ | awk ‘{print $10}’`
if [ $check -gt 20 ]
then
echo “Server load too high ($check), kill all the following program: httpd, php, mysqld”
killall httpd
killall php
killall mysqld
else
echo “Server load OK ($check)”
fi

echo “—————-“