Tomcat 自动监控脚本
来源:互联网 发布:橡胶木家具 知乎 编辑:程序博客网 时间:2024/05/16 02:31
脚本监控Tomcat服务,当服务死掉后脚本自动重启服务。
1、将本脚本保存为/root/tcautorestart.sh,并给执行权限。
#!/bin/bash
if [[ -e /root/tcstatus.log ]];then
cp -f /dev/null /root/tcstatus.log
fi
/usr/local/bin/lynx -dump -connect_timeout=15000 -error_file=/root/tcstatus.log /
http://downtheme.somode.com:8080/index.jsp >/dev/null ##index.jsp为用于测试的jsp页
cat /root/tcstatus.log | grep "STATUS=HTTP/1.1 200 OK" >/dev/null
if (( $? != 0 ));then
{
#shutdown tomcat
date >> /root/tcrestart.log
while true
do
/usr/local/tomcat/bin/shutdown.sh >> /root/tcrestart.log
sleep 20
cp -f /dev/null /root/process.tc
ps -aux | awk '$0 ~ /java.*tomcat/{print $0}' > /root/process.tc
cat process.tc | grep "java.*tomcat" > /dev/null
if (( $? == 0 ));then
continue
else
{
echo "Tomcat shutdown success!" >> /root/tcrestart.log
break
}
fi
done
#startup tomcat
while true
do
/usr/local/tomcat/bin/startup.sh >> /root/tcrestart.log
sleep 5
cp -f /dev/null /root/process.tc
ps -aux | awk '$0 ~ ///bin//java/{print $0}' > /root/process.tc
cat process.tc |grep "/bin/java" > /dev/null
if (( $? == 0 ));then
{
echo "Tomcat restartup success!" >> /root/tcrestart.log
break
}
else
continue
fi
done
}
else
exit 0
fi
2、安装lynx
# tar -xzvf lynx2.8.5.tar.gz
# cd ynx2.8.5
# make
# make install ##lynx默认安装到/usr/local/lynx下
# ln -s /usr/local/lynx /bin ##注意自动化任务的path变量和bash的可能不同,
##一个能在bash中运行的很好的脚本不一定在cron中运行的很好,有些命令可能在cron中找不到
3、将tomcat自启动脚本加到cron中
# crontab -e
#tomcat auto restart自动重启
*/5 * * * * /root/tcautorestart.sh > /dev/null 2>&1
参考:
得到网页的返回状态:
[root@toolsbook root]# lynx -dump -connect_timeout=15000 -error_file=/root/test1.log /
http://downtheme.somode.com:8080/index.jsp
0 ##显示浏览页的内容
[root@toolsbook root]# less /root/test1.log ##网页的返回状态信息
URL=http://downtheme.somode.com:8080/index.jspdf (GET)
STATUS=HTTP/1.1 404 /index.jspdf ##网页不存在,返回404错误
URL=http://downtheme.somode.com:8080/index.jsp (GET)
STATUS=HTTP/1.1 200 OK ##网页能正常访问
lynx参数:
-dump :显示网页内容到标准输出并推出
-connect_timeout :设置超时时间,单位(毫秒)
-error_file :将网页的返回状态信息写进文件
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/diy8187/archive/2009/07/22/4369120.aspx
- Tomcat 自动监控脚本
- Tomcat 自动监控脚本
- shell自动监控重启Tomcat脚本
- shell自动监控重启Tomcat脚本
- shell自动监控重启Tomcat脚本
- shell自动监控重启Tomcat脚本
- 监控tomcat服务自动重新启动shell脚本
- Linux下使用shell脚本自动监控重启tomcat
- Linux下使用shell脚本自动监控重启tomcat
- shell自动监控重启Tomcat脚本,每一分钟检查
- 监控memcache tomcat脚本
- 监控tomcat服务脚本
- bash脚本: 监控Tomcat
- 自动监控脚本
- tomcat监控重启脚本
- tomcat自动启动脚本,
- mysql 集群自动监控脚本
- linux shell脚本定时3分钟监控Tomcat,自动重启
- 物联网(The Internet of things) - 问题(9)
- 物联网(The Internet of things) - 需要解决的五大问题(8)
- 南水北调
- 物流公司运输最优路线问题
- JS扫雷
- Tomcat 自动监控脚本
- 检测tomcat服务状态,自动重启Tomcat
- 安装IIS详解
- TextBox JavaScript 只允许输入数字或字母
- 2010年十大关键IT技术概览:云计算最受关注
- 关于“远程桌面连接已断开”问题的处理(转)
- OOD
- C# 里弹出“确定”“取消”对话框
- OOA/D