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

相关推荐
dvjr cloi14 小时前
Linux(CentOS)安装 MySQL
linux·mysql·centos
运维全栈笔记1 天前
Linux安装配置Tomcat保姆级教程:从部署到性能调优
linux·服务器·中间件·tomcat·apache·web
何中应1 天前
CentOS 7安装、卸载MySQL数据库(二)
数据库·mysql·centos
PESS ABIN2 天前
JavaWeb项目打包、部署至Tomcat并启动的全程指南(图文详解)
java·tomcat
ShiJiuD6668889992 天前
Request和Response
tomcat
BduL OWED2 天前
Docker:基于自制openjdk8镜像 or 官方openjdk8镜像,制作tomcat镜像
docker·容器·tomcat
misL NITL2 天前
idea、mybatis报错Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
tomcat·intellij-idea·mybatis
idolao2 天前
CentOS 7 安装 jakarta-tomcat-connectors-jk2-src-current.tar.gz 详细步骤(解压、编译、配置)
linux·centos·tomcat
薪火铺子3 天前
SpringBoot WebServer启动与监听器原理深度解析
spring boot·后端·tomcat
HABuo3 天前
【linux(四)】套接字编程--基于UDP协议的客户端服务端
linux·服务器·c++·网络协议·ubuntu·udp·centos