1.写一个shell脚本test.sh,重新启动tomcat
#!/bin/sh. /etc/profilepid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'`echo $pidif [ -n "$pid" ]then{ echo ===========shutdown================ /opt/tomcat/bin/shutdown.sh sleep 1 pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'` if [ -n "$pid" ] then { sleep 1 echo ========kill tomcat============== kill -9 $pid } fi sleep 1 echo ===========startup.sh============== /opt/tomcat/bin/startup.sh }elseecho ===========startup.sh==============/opt/tomcat/bin/startup.shfi
2.把test.sh文件放到root目录下
3.提高权限
chmod a+x test.sh
4.在控制台上输入以下命令
crontab -e
5.按i键编辑这个文本文件,输入以下内容,每天凌晨4:30重启tomcat
30 04 * * * /root/test.sh
按esc键退出编辑,输入wq回车保存
6.启动定时服务
[root@]# service crond stop
[root@]# service crond start