1.创建脚本文件
vim autoRest.sh(若不存在autoRest.sh,会自动创建)
2.查询tomcat进程,kill 掉tomcat进程,执行./startup.sh启动
#!/bin/bash
ps -ef | grep apache-tomcat-7 | grep -v 'grep'| awk '{print $2}'|xargs kill -9
cd /usr/local/apache-tomcat-7/bin
./startup.sh
注意: 脚本中必须要有 !/bin/bash ,否则在定时任务中无法执行
3.将.sh 变为可执行文件
chmod +x filename 例如:chmod +x autoRest.sh
二.配置定时任务
1.编辑定时文件
vim /etc/crontab
2.添加每天凌晨1点执行一次:
0 0 1 * * ? root /autoRest.sh
如果需要其他配置规则,请参考cron表达式写法
3.重新加载cron 服务
linux下 crontab服务对应的是crond服务。
`service crond restart`
centos7系统下服务可以通过systemctl来重启
systemctl restart crond`