linux 负载报警脚本第一版

linux 负载报警脚本,系统负载超过一定数值,就重启php-cgi,并发送报警短信。

#!/bin/sh  
#description:system load average  
#author:coralzd powered by www.freebsdsystem.org  
host=$(hostname)  
channel=$(hostname | sed 's/[0-9]//g')  
runday=$(date "+%Y-%m-%d")  
IPhost=$(/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')  
i=10  
  while [ 1 ];do 
rundaytime=$(date "+%Y-%m-%d %H:%M:%S")  
L=$(cat /proc/loadavg|cut -c1-4)  
RESULT=$(echo "$L > $i"|bc)  
if [ "${RESULT}" == "$i" ]; then  
echo "$runday" >> /var/tmp/${host}.txt  
wget http: -O /dev/null >/dev/null 2>&1 //10.10.10.10/phpsms/smsu.php?phone=15012345678\&msg=warning%20${IPhost}%20Load%20avarage%20is%20high 
/usr/local/php52/sbin/php-fpm restart  
echo "${runday}" >> /var/log/${host}.txt  
echo "The system load average is 10+ ,php-fpm already restart" >> /var/log/${host}.txt  
fi  
sleep 600  
done