分享:监控tomcat并执行间隔报警脚本
时间:2015-08-04 17:38来源:linux.it.net.cn 作者:IT
-
#!/bin/bash
-
time=`date +"%Y-%m-%d/%H:%M:%S"`
-
mail_send() {
-
send_time=`date +"%s"`
-
txt="echo $1 is error!"
-
ip=`ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-`
-
if [ -f /data/logs/send_log ];then
-
last_time=`cat /data/logs/send_log`
-
else
-
last_time=1285377000
-
fi
-
mid_time=`expr $send_time - $last_time`
-
if [ $mid_time -gt 300 ];
-
then
-
echo $txt | mutt -s "xx.com_$ip" 138XXXXXXXX@139.com
-
echo $send_time > /data/logs/send_log
-
fi
-
}
-
while true;
-
do
-
http_jsp_code=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://127.0.0.1/index.jsp`
-
http_img_code=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://127.0.0.1/images/logo.png`
-
if [ x$http_jsp_code != "x200" ];
-
then
-
if [ x$http_img_code != "x200" ];
-
then
-
a=`netstat -ntpl|grep nginx`
-
if [ -z $a ];then
-
/root/nginx_start
-
fi
-
/root/nginx_reload
-
echo "at $time nginx restart!" >> /data/logs/nginx_restart.log
-
fi
-
/bin/rm -rf /usr/local/tomcat/work/Catalina/*
-
/root/tomcat_restart
-
echo "at $time tomcat restart!" >> /data/logs/tomcat_restart.log
-
mail_send tomcat
-
fi
-
sleep 10
-
done
(责任编辑:IT) |
------分隔线----------------------------