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>
            标题URL:<a href="http://www.apyobr.com/article/jjjpjd.html">http://www.apyobr.com/article/jjjpjd.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/ddghdph.html">帝国cms删除友情链接 帝国cms删除友情链接怎么删</a>
                </li><li>
                    <a href="/article/ddghdgo.html">腾讯云服务器需要那些 腾讯云服务器需要那些设备</a>
                </li><li>
                    <a href="/article/ddghcoo.html">vb点虐
带参exe的简单介绍</a>
                </li><li>
                    <a href="/article/ddghdpj.html">把文件存在服务器上安全吗 文件服务器是不是只能放文件</a>
                </li><li>
                    <a href="/article/ddghdjo.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:18982081108" target="_blank">18982081108</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/yunying.html" target="_blank">成都网站托管</a><a href="https://www.cdcxhl.com/hangyead/" target="_blank">1元广告</a><a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌推广公司</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">成都外贸网站建设公司</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">免费收录网站</a><a href="https://www.cdcxhl.com/wangzhandingzhi.html" target="_blank">成都定制网站网页设计</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">成都响应式网站设计</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">微信小程序开发公司</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">成都微信小程序开发</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文营销</a><a href="https://www.cdcxhl.com/app.html" target="_blank">成都app软件开发公司</a><a href="https://www.cdcxhl.com/link/" target="_blank">友情链接购买</a><a href="https://www.cdcxhl.com/link/" 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/yunying.html" target="_blank">网站运营</a><a href="https://www.cdcxhl.com/ddos/" target="_blank">高防IP防护</a><a href="https://www.cdcxhl.com/weihu/" target="_blank">成都网站维护公司</a>            </div>
        </div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="footNav">
                <h3>网站建设</h3>
                <a href="https://www.cdcxhl.com/mianfei/jianshe/chengdu.html" target="_blank">成都免费网站建设公司</a><a href="http://m.cdcxhl.cn/qiye/" target="_blank">成都网站建设公司</a><a href="https://www.cdxwcx.com/wangzhan/pinpai.html" target="_blank">品牌网站建设</a>            </div>
            <div class="footNav">
                <h3>服务器托管</h3>
                <a href="http://www.cdfuwuqi.com/tuoguan/duoxian/" target="_blank">多线服务器托管</a><a href="https://www.cdcxhl.com/tuoguan/zongshu/" target="_blank">成都棕树机房</a><a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" target="_blank">绵阳服务器托管</a>            </div>
            <div class="footNav">
                <h3>网站制作</h3>
                <a href="http://chengdu.cdxwcx.cn/" target="_blank">成都网站制作</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站制作</a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站制作</a>            </div>
            <div class="footNav">
                <h3>企业服务</h3>
                <a href="https://www.cdcxhl.com/service/gongsizhuce.html" target="_blank">注册公司</a><a href="https://www.cdcxhl.com/service/icpxuke.html" target="_blank">互联网信息经营许可证</a><a href="https://www.cdcxhl.com/shoulu/" 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="https://www.cdcxhl.com/xiaochengx.html">小程序开发</a>、<a href="https://www.cdcxhl.com/app.html">APP开发</a>、
                        <a href="https://www.cdcxhl.com/yingxiao.html">营销型网站建设</a>、<a href="https://www.cdxwcx.com/">网站建设</a>、
                        <i><a href="https://www.cdcxhl.com/wangzhandingzhi.html">网站定制开发</a></i> ,就选<a href="http://www.apyobr.com/">灿优商贸</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="bottom container">
            <p class="fl">
                版权所有:大悟县灿优商贸有限公司
                备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">鄂ICP备2025125667号-8</a>
                服务热线:18982081108
            </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="#" 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>