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

相关推荐
HABuo8 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
invicinble10 小时前
对tomcat的提供的功能与底层拓扑结构与实现机制的理解
java·tomcat
2301_8187320612 小时前
前端调用控制层接口,进不去,报错415,类型不匹配
java·spring boot·spring·tomcat·intellij-idea
程序员敲代码吗17 小时前
Spring Boot与Tomcat整合的内部机制与优化
spring boot·后端·tomcat
礼拜天没时间.20 小时前
深入Docker架构——C/S模式解析
linux·docker·容器·架构·centos
礼拜天没时间.1 天前
自定义镜像制作——从Dockerfile到镜像
linux·docker·容器·centos·bash
怜渠客2 天前
彻底告别 FireFox 浏览器
firefox
林深现海2 天前
Jetson Orin nano/nx刷机后无法打开chrome/firefox浏览器
前端·chrome·firefox
予枫的编程笔记2 天前
【Linux入门篇】Ubuntu和CentOS包管理不一样?apt与yum对比实操,看完再也不混淆
linux·人工智能·ubuntu·centos·linux包管理·linux新手教程·rpm离线安装
954L2 天前
CentOs7执行yum update出现链接404问题
linux·centos·yum·vault