shell指令碼:定時重啟tomcat服務
阿新 • • 發佈:2019-02-19
1.編寫test.sh指令碼,指令碼如下:
#!/bin/sh export JAVA_HOME=/usr/java/jdk1.6.0_26 pid=`ps -auxww|grep tomcat|grep -v grep|awk '{print $2}'` echo $pid if [ -n "$pid" ]; then { echo "==========tomcat is start============" '/usr/server/tomcat-7.0.27/bin/shutdown.sh' sleep 5 '/usr/server/tomcat-7.0.27/bin/shutdown.sh' sleep 15 pid=`ps -auxww|grep tomcat|grep -v grep|awk '{print $2}'` if [ -n "$pid" ]; then { echo "======to kill the tomcat pid $pid========" kill $pid sleep 3 } fi echo "==========start tomcat============" '/usr/server/tomcat-7.0.27/bin/startup.sh' } else { echo "==========tomcat is stop=====start=======" '/usr/server/tomcat-7.0.27/bin/startup.sh' } fi
2.在新建任務計劃:利用crontab -e命令,於02:00執行重啟服務
10 02 * * * /usr/server/tomcat-7.0.27/bin/startup.sh
3.啟動crond服務 命令如下
3.啟動定時服務
[root@]# service crond stop
[root@]# service crond start
4.檢視該任務是否在定時列表裡面:
[root@]# crontab -l
10 02 * * * /usr/server/tomcat-7.0.27/bin/startup.sh