本篇文章给大家分享的是有关Linux 中怎么利用Shell脚本检测tomcat,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
Linux Shell脚本检测tomcat并自动重启
后台运行命令 sh xxx.sh &
查看后台任务:jobs
召唤到前台:fg jobs编号
可以删掉while循环的代码放到crontab里面定时执行,可以将脚本直接后台运行,
#!/bin/bash
while [ true ]
do
url="https://www.tdyun.com/";
httpOK=`curl --connect-timeout 10 -m 60 --head --silent $url | awk 'NR==1{print $2}'`;
if [ $httpOK == "200" ];then
tomcat6=`ps -ef | grep tomcat | awk 'NR==1{print $1" "$2;}'`;
user=`echo $tomcat6 | awk 'NR==1{print $1}'`;
pid=`echo $tomcat6 | awk 'NR==1{print $2}'`;
if [ $user != "tomcat" ]; then
service tomcat6 start;
else
kill -9 $pid;sleep 5s;service tomcat6 start;service tomcat6 start;service tomcat6 status;
fi;
fi;
sleep 5m;
done;
以上就是Linux 中怎么利用Shell脚本检测tomcat,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注天达云行业资讯频道。