centos 定时脚本检测tomcat是否启动,未启动情况下重新启动

编写脚本

tomcatMonitor.sh

bash 复制代码
#!/bin/sh

. /etc/profile
. ~/.bash_profile


#首先用ps -ef | grep tomcat 获得了tomcat进程信息,这样出来的结果中会包含grep本身,
#因此通过 | grep -v grep 来排除grep本身,然后通过 awk '{print $2}'来打印出要找的进程id号;
pid=$(ps -ef|grep apache-tomcat-8.5.47 |grep -v grep | awk '{print $2}') 
#echo $pid

if [ -n "$pid" ];then  
    echo "tomcat进程ID为:$pid. 运行正常" 
else  
  echo "进程不存在! Tomcat自动重启"  
  cd /usr/local/apache-tomcat-8.5.47/bin/ &&  ./startup.sh
fi 

为脚本添加可执行权限

bash 复制代码
chmod u+x tomcatMonitor.sh

配置定时任务

bash 复制代码
*/30 * * * * /usr/local/tomcatMonitor.sh

重启定时任务:systemctl start crond

相关推荐
wsad053215 分钟前
CentOS 7 Minimal 配置静态 IP 完整指南(VMware NAT 模式)
linux·tcp/ip·centos
市安36 分钟前
基于Centos构建Nginx镜像(Dokerfile)
linux·运维·nginx·docker·容器·centos·镜像
hzc09876543212 小时前
报错The default superclass, “jakarta.servlet.http.HttpServlet“(已经配置好tomcat)
http·servlet·tomcat
p***19941 天前
SpringBoot项目中替换指定版本的tomcat
spring boot·后端·tomcat
小心草里有鬼2 天前
VMware虚拟机扩容
linux·后端·centos·vim
Tinyundg2 天前
CentOS安装Oracle 19C 数据库
数据库·oracle·centos
何中应2 天前
CentOS7安装Git
运维·git·centos·开发工具
礼拜天没时间.2 天前
容器网络配置——从互联到自定义桥接
运维·网络·docker·容器·centos
_codemonster2 天前
配置Tomcat时为啥要配置Artifacts
java·tomcat·firefox
fengsen52113142 天前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat