大致环境是这样的
在目录/opt/rfid下有一个tomcat文件夹,叫做apache-tomcat-7.0.42,现在需要每天定时重启tomcat。
一、 使用touch 命令创建sh脚本
1.新建restart-cs.sh文件
touch restart-cs.sh
2.编辑脚本内容 vi restart-cs.sh
#! /bin/sh
ps -ef|grep apache-tomcat-7.0.42|grep java|awk '{print $2}'|xargs kill -9
sh /opt/rfid/apache-tomcat-7.0.42/bin/startup.sh
3.保存脚本,修改权限可执行
chmod 777 restart-cs.sh
4.在crontab 中编写定时任务
输入crontab -e
05 04 * * * /opt/rfid/apache-tomcat-7.0.42/restart-cs.sh
保存,收工。
另外,可以先手动执行一下脚本看看能否正常执行。GOOD LUCK!