食品网站建设需求分析,高端网站建设公司,网站租用价格,杭州推广公司排名编写脚本
tomcatMonitor.sh
#!/bin/sh. /etc/profile
. ~/.bash_profile#首先用ps -ef | grep tomcat 获得了tomcat进程信息#xff0c;这样出来的结果中会包含grep本身#xff0c;
#因此通过 | grep -v grep 来排除grep本身#xff0c;然后通过 awk {print $2}来打印出要…编写脚本
tomcatMonitor.sh
#!/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 $pidif [ -n $pid ];then echo tomcat进程ID为:$pid. 运行正常
else echo 进程不存在! Tomcat自动重启 cd /usr/local/apache-tomcat-8.5.47/bin/ ./startup.sh
fi 为脚本添加可执行权限
chmod ux tomcatMonitor.sh配置定时任务
*/30 * * * * /usr/local/tomcatMonitor.sh重启定时任务systemctl start crond