shell脚本重启tomcat
最近遇到了晚上10点要求重启tomcat,但我又不想守在机器前操作,直接找了个shell脚本让其定时重启tomcat,这样让我很轻松.
系统:centos 7.x(64位)
1.重启脚本
cat /root/soft_shell/retomcat.sh
#!/bin/bash . /etc/profile pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'` path="/usr/local/tomcat" if [ -n "$pid" ] then { echo ===========shutdown================ $path/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============== $path/bin/startup.sh } else echo ===========startup.sh============== $path/bin/startup.sh fi
2.crontab定时任务
crontab -l
0 22 * * * /bin/bash /root/soft_shell/retomcat.sh
好了,一个定时重启tomcat的脚本就搞定了.
评论: