1、确认crontab是否安装
crontab -l
//返回no crontab for root,表示已安装
2、生成重启tomcat文件
vim tomcatStart.sh
#!/bin/bash
/etc/profile
echo $JAVA_HOME
#这里取jdk路径
export JAVA_HOME=/usr/java/jdk1.8.0_191
#这里取tomcat路径
tomcatPath="/data2/webapp/apache-tomcat-8.5.78-gspws"
binPath="$tomcatPath/bin"
echo "[info][$(date)]....tomcat.....$tomcatPath"
SHUTDOWN=$binPath"/shutdown.sh"
STARTTOMCAT=$binPath"/startup.sh"
echo "[info][$(date)]....shutdown...."
$SHUTDOWN
sleep 2
pid=`ps -ef | grep tomcat | grep -w ${tomcatPath} | grep -v 'grep' | awk '{print $2}'`
if [ -n "$pid" ]; then
echo "[info][$(date)]..shutdown.......kill $pid.."
kill -9 $pid;
echo "[info][$(date)]kill $pid...."
fi
echo "[info][$(date)]10..........$tomcatPath.tomcat"
sleep 10
$STARTTOMCAT
3、给启动文件授权
sudo chmod 777 tomcatStart.sh
4、创建定时任务
crontab -e
// 第一个是 tomcatStart.sh 的路径, 第二个是将日志输出到某个文件中
*/2 * * * * /home/tomcat/tomcatStart.sh >> /home/tomcat/tomcatLog.txt
5、重启定时服务
systemctl restart crond
#重启后通过crontab -l 可以查询到定时任务
标签:info,tomcat,crontab,centos7,sh,tomcatPath,date,定时 From: https://www.cnblogs.com/sumling/p/17332840.html