写了一个监控tomcat程序。在日志中tomcatservicecode值是空的。
【代码】
Monitor()
{
echo "[info]开始监控tomcat...[$(date +'%F %H:%M:%S')]"
if [[ $TomcatCount -gt 0 ]];then
echo "[info]当前tomcat进程ID为:$TomcatID,继续检测页面..."
#检测是否启动成功
TomcatServiceCode=$(curl -s -o $GetPageInfo -m 10 --connect-timeout 10 $ WebUrl -w %{http_code})
if [ $TomcatServiceCode -eq 200 ];then
echo "[info]页面返回码为:$TomcatServicCode,tomcat启动成功,页面正常.. ."
else
echo "[error]tomcat页面出错,状态码为:$TomcatServicCode,错误日志已输 出到$GetPageInfo"
echo "[info]页面访问出错,开始重启tomcat"
kill -9 $TomcatID
sleep 3
rm -rf $TomcatCache #清理tomcat缓存
echo "[info]现在开始重启tomcat..."
echo "[info]请稍后..."
fi
else
echo "[error]tomcat 进程不存在!"
echo "[info]获取信息TomcatID:$TomcatID"
echo "[info]获取信息TomcatCount:$TomcatCount"
echo "[info]tomcat开始自动重启"
echo "[info]$StartTomcat,请稍后......"
rm -rf $TomcatCache
$StartTomcat
fi
echo "--------------------------------------"
}
【日志】
--------------------------------------
[info]开始监控tomcat...[2019-01-04 14:54:01]
[info]当前tomcat进程ID为:8112,继续检测页面...
[info]页面返回码为:,tomcat启动成功,页面正常...
--------------------------------------
[info]开始监控tomcat...[2019-01-04 14:55:01]
[info]当前tomcat进程ID为:8112,继续检测页面...
[info]页面返回码为:,tomcat启动成功,页面正常...
--------------------------------------
[info]开始监控tomcat...[2019-01-04 14:56:01]
[info]当前tomcat进程ID为:8112,继续检测页面...
[info]页面返回码为:,tomcat启动成功,页面正常...
-------------------------------------