当前位置: > Linux服务器 > Tomcat >

分享:监控tomcat并执行间隔报警脚本

时间:2015-08-04 17:38来源:linux.it.net.cn 作者:IT
  1. #!/bin/bash

  2. time=`date +"%Y-%m-%d/%H:%M:%S"`

  3. mail_send() {

  4. send_time=`date +"%s"`

  5. txt="echo $1 is error!"

  6. ip=`ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-`

  7. if [ -f /data/logs/send_log ];then

  8. last_time=`cat /data/logs/send_log`

  9. else

  10. last_time=1285377000

  11. fi

  12. mid_time=`expr $send_time - $last_time`

  13. if [ $mid_time -gt 300 ];

  14. then

  15. echo $txt | mutt -s "xx.com_$ip" 138XXXXXXXX@139.com

  16. echo $send_time > /data/logs/send_log

  17. fi

  18. }

  19. while true;

  20. do

  21. http_jsp_code=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://127.0.0.1/index.jsp`

  22. http_img_code=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://127.0.0.1/images/logo.png`

  23. if [ x$http_jsp_code != "x200" ];

  24. then

  25.     if [  x$http_img_code != "x200" ];

  26.         then

  27.          a=`netstat -ntpl|grep nginx`

  28.         if [ -z $a ];then

  29.         /root/nginx_start

  30.         fi

  31.         /root/nginx_reload

  32.         echo "at $time nginx restart!" >> /data/logs/nginx_restart.log

  33.     fi

  34.   /bin/rm -rf /usr/local/tomcat/work/Catalina/*

  35.   /root/tomcat_restart

  36.   echo "at $time tomcat restart!" >> /data/logs/tomcat_restart.log

  37.   mail_send tomcat

  38. fi

  39. sleep 10

  40. done
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容