Linux中怎么使用Crontab定时监测维护Tomcat应用程序-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

Linux中怎么使用Crontab定时监测维护Tomcat应用程序

这篇文章主要介绍“Linux中怎么使用Crontab定时监测维护Tomcat应用程序”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Linux中怎么使用Crontab定时监测维护Tomcat应用程序”文章能帮助大家解决问题。

成都创新互联专注于绩溪网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供绩溪营销型网站建设,绩溪网站制作、绩溪网页设计、绩溪网站官网定制、微信小程序定制开发服务,打造绩溪网络公司原创品牌,更为您提供绩溪网站排名全网营销落地服务。

监测的应用接口: 新闻接口、天气接口
处理方法:应用接口不可用时自动重启tomcat,并发送告警邮件给相关人员

#!/bin/bash
#---------------------------------------------------------
# 功能说明:
#	监控指定http服务是否可用,如果不可用立即重启tomcat
#
# 使用说明:
#	1. 将此脚本放置在/home/opentsp/crontab/目录下。
#	2. 修改脚本执行权下为可执行权限。
#	3. 添加到定时任务中,定时执行时间(建议为20分钟)
#	4. 修改邮件发送人员信息列表(当服务重启时发邮件给相关人员)
#                    - 周凌飞(2014-08-13)
#---------------------------------------------------------
export lc_all=zh_cn.utf-8

#网站地址、参数
server_name="趣驾云接口服务"
url_2="http://127.0.0.1/get_rss_news?p=%7b%27chid%27:%27tiyu%27%7d"
keyworld_2=''
url_3="http://127.0.0.1/get_json_weather?p=%7blon:116.407617,lat:39.993956,date:1%7d"
keyworld_3='temperature'

#邮件发送列表
mail_ary=(
xxxxxxxxx@navinfo.com
xxxxxxxxx@navinfo.com
xxxxxxxxx@navinfo.com
)

#接口调用失败的处理方法
function dofail(){
	local ipinfo=$(ifconfig |sed -n '2p'|awk '{print substr($2,6)}');
	# 发送邮件
	for _v in ${mail_ary[*]} ; do
		echo "[$server_name 异常] - [$(date -d "0 min" +"%y-%m-%d %h:%m:%s")] - [请求地址: $1] - [请求返回码: $2]" | mail -s ${ipinfo}服务异常 ${_v}
	done
	# 写入日志
	echo "[error] - [$(date -d "0 min" +"%y-%m-%d %h:%m:%s")] - 返回码[$2] - 重启tomcat服务" >> detect-http.log
	# 关闭tomcat
	sh /home/opentsp/crontab/ibr-shutdown.sh
	exit;
}

#请求超时时间设置
time_out=40
function docheck(){
	local url_x=$1;
	local keyworld_x=$2;
	http_status_code=`curl -m $time_out -o /dev/null -s -w "%{http_code}" "${url_x}"`
	if [ $http_status_code != 200 ];then
		#请求失败
		echo "-> fail - 返回码${http_status_code}";
		dofail ${url_x} ${http_status_code};
	else
		#<a title="服务器" target="_blank" href="http://www.cdfuwuqi.com/">服务器</a>正常响应,检查返回内容
		if curl -m ${time_out} -s ${url_x} | grep -q ${keyworld_x};then
			echo "-> success";
		else
			echo "->> fail";
			# 返回内容错误处理
			dofail ${url_x} ${http_status_code};
		fi
	fi
}

#
#检查 - 新闻
docheck ${url_2} ${keyworld_2}
#检查 - 天气
docheck ${url_3} ${keyworld_3}</pre><p>将以上代码放入到linux的定时任务中即可,定时任务时间建议为20分钟一次。</p><p>关于“Linux中怎么使用Crontab定时监测维护Tomcat应用程序”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注创新互联行业资讯频道,小编每天都会为大家更新不同的知识点。</p>            
            
                        <br>
            当前名称:Linux中怎么使用Crontab定时监测维护Tomcat应用程序            <br>
            当前路径:<a href="http://kswsj.cn/article/jjjpjd.html">http://kswsj.cn/article/jjjpjd.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/sdcejc.html">网站网页设计培训的主要内容网页设计的总体要求</a>
                </li><li>
                    <a href="/article/sdcipg.html">域名一年多少钱,具体是如何定价的?</a>
                </li><li>
                    <a href="/article/sdcijd.html">北京好的网站建设公司具备那些要素?用户该如何选择?</a>
                </li><li>
                    <a href="/article/sdcige.html">如何购买域名?域名注册申请表应包括哪些?</a>
                </li><li>
                    <a href="/article/sdcihc.html">我国大数据应用范围持续扩大广东、福建企业密度较为集中</a>
                </li>        </ul>
    </div>
</div>
<div class="line"></div>
<!--底部-->
<footer id="5">
    <div class="foot1 container">
        <div class="list">
            <div class="item">
                <a href="javascript:;">
                    <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span>
                    <strong>关注我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>索要报价</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>我要咨询</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>找到我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>投诉建议</strong>
                </a>
            </div>
        </div>
        <div class="tel">
            <dl>
                <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br>
                <span>也许您需要专业的服务,欢迎来电咨询</span>
            </dl>
            <dl>
                <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br>
                <span>您的需求,是我们前进的动力</span>
            </dl>
        </div>
    </div>
    <div class="friend">
        <div class="container">
            <span class="tit">友情链接:</span>
            <div class="inner">
                <a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌推广</a><a href="https://www.cdcxhl.com/zuyong/" target="_blank">成都服务器租用</a><a href="https://www.cdcxhl.com/link/" target="_blank">外链</a><a href="https://www.cdcxhl.com/" target="_blank">网站制作</a><a href="https://www.cdcxhl.com/" target="_blank">建站</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">发布软文</a><a href="https://www.cdcxhl.com/seo.html" target="_blank">成都网站推广</a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">成都营销型网站建设</a><a href="https://www.cdcxhl.com/app.html" target="_blank">成都app软件开发公司</a><a href="https://www.cdcxhl.com/hangyead/" target="_blank">一元广告</a><a href="https://www.cdcxhl.com/" target="_blank">网站设计</a><a href="https://www.cdcxhl.com/mobile.html" target="_blank">成都手机网站制作</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">成都外贸网站建设公司</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">成都微信小程序开发</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站设计公司</a><a href="https://www.cdcxhl.com/weihu/" target="_blank">成都网站维护</a><a href="https://www.cdcxhl.com/mobile.html" target="_blank">成都手机网站建设公司</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文投放</a>            </div>
        </div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="footNav">
                <h3>网站建设</h3>
                <a href="http://m.cdcxhl.cn/qiye/" target="_blank">成都企业网站建设</a><a href="https://www.cdxwcx.com/city/shifang/" target="_blank">什邡网站建设</a><a href="http://www.cdkjz.cn/fangan/store/" target="_blank">成都电商网站建设方案</a>            </div>
            <div class="footNav">
                <h3>服务器托管</h3>
                <a href="https://www.cdcxhl.com/idc/ziyang.html" target="_blank">资阳天府云计算中心</a><a href="https://www.cdcxhl.com/tuoguan/zongshu/" target="_blank">成都棕树机房</a><a href="http://www.cdfuwuqi.com/tuoguan/duoxian/" target="_blank">多线服务器托管</a>            </div>
            <div class="footNav">
                <h3>网站制作</h3>
                <a href="http://chengdu.cdxwcx.cn/" target="_blank">成都网站制作</a><a href="http://m.cdcxhl.cn/mobile/" target="_blank">手机网站制作</a><a href="http://seo.cdkjz.cn/wangzhan/" target="_blank">网站制作公司</a>            </div>
            <div class="footNav">
                <h3>企业服务</h3>
                <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站快速收录</a><a href="https://www.cdcxhl.com/service/guangdianxuke.html" target="_blank">广播电视节目制作许可证</a><a href="https://www.cdcxhl.com/service/beian.html" target="_blank">网站备案</a>            </div>
            <div class="fr ecode">
                <div class="fl">
                    <img src="/Public/Home/img/ewm.jpg">
                    <p>关注企业微信</p>
                </div>
                <div class="fr slogan">
                    <p class="icon">
                        <a class="ph" href=""><i class="iconfont"></i></a>
                        <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a>
                    </p>
                    <p>
                        <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、
                        <a href="">营销型网站建设</a>、<a href="">网站建设</a>、
                        <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="bottom container">
            <p class="fl">
                版权所有:成都创新互联科技有限公司
                备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a>
                服务热线:028-86922220
            </p>
            <p class="fr">
                <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:
                <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a>
            </p>
        </div>
    </div>
</footer>
<!--在线咨询-->
<div class="fot">
    <ul>
        <li>
            <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank">
                <img src="/Public/Home/img/fot1.png" alt="">
                <p>在线咨询</p>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" target="_blank">
                <img src="/Public/Home/img/fot2.png" alt="">
                <p>拨打电话</p>
            </a>
        </li>
    </ul>
</div>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>