Home > System Tutorial > LINUX > body text

Solution to the problem of regularly restarting tomcat script and not executing it after adding crontab

PHPz
Release: 2024-07-19 11:07:03
Original
589 people have browsed it

定时重启 tomcat 脚本加入 crontab 后不执行的解决方法

在网上找了一个定时重启tomcat的脚本,自己自动执行是可以的,但就是加入crontab后不执行。

重启脚本如下

restart_tomcat.sh

#!/bin/bash
tomcat_home=/usr/local/tomcat8
SHUTDOWN=$tomcat_home/bin/shutdown.sh
STARTTOMCAT=$tomcat_home/bin/startup.sh
$SHUTDOWN
$STARTTOMCAT
Copy after login

定时任务

0 2 * * * cd /opt && ./restart_tomcat.sh
Copy after login

定时任务执行后提示信息在/var/spool/mail/root中

cat /var/spool/mail/root
Copy after login

还可以在crontab的执行日志中看都执行了什么命令

tail -n 100 /var/log/cron
Copy after login

定时执行任务软件安卓_定时执行任务app_linux定时任务不执行

从提示信息中我们看见是在执行脚本的时侯没有找到JAVA_HOME

在网上也找到了一篇文章中介绍的

有时我们创建了一个crontab,然而这个任务却难以手动执行,而自动执行这个任务却没有问题,这些情况通常是因为在crontab文件中没有配置环境变量导致的。

所以就改了一下重启脚本linux定时任务不执行,加入source/etc/profile

最终的重启脚本如下

#!/bin/sh
source /etc/profile
tomcat_home=/usr/local/tomcat8
# 找到tomcat进程并kill掉
ps -ef |grep tomcat |awk {'print $2'} |sed -e "s/^/kill -9 /g" |sh -
# 删除日志目录
# rm $tomcat_home/logs/* -rf
# 删除临时目录
# rm $tomcat_home/work/* -rf
# 启动tomcat
start_tomcat=$tomcat_home/bin/startup.sh
$start_tomcat
Copy after login

定时执行任务app_定时执行任务软件安卓_linux定时任务不执行

此次才能重启了,还是linux知识把握的太少linux定时任务不执行linux启动盘制作工具linux操作系统教程,没有系统地了解。

注意事项:crontab中要写全路径

参考文献

重启tomcat脚本

crontab定时执行

The above is the detailed content of Solution to the problem of regularly restarting tomcat script and not executing it after adding crontab. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!