1.先上脚本restart.sh
#!/bin/sh
. /etc/profile
pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'`
echo $pid
if [ -n "$pid" ]
then
{
echo ===========shutdown================
/usr/local/apache-tomcat-8.0.9/bin/shutdown.sh
sleep 1
pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'`
if [ -n "$pid" ]
then
{
sleep 2
echo ========kill tomcat==============
kill -9 $pid
}
fi
sleep 1
echo ===========startup.sh==============
/usr/local/apache-tomcat-8.0.9/bin/startup.sh
}
else
echo ===========startup.sh==============
/usr/local/apache-tomcat-8.0.9/startup.sh
fi
2.把restart.sh放置一位置,如/usr/local/
3.使用命令添加定时任务
crontab -e
在其中加入下面的文本
#每天早上5点重启tomcat
0 5 * * * /usr/local/restart.sh
保存退出-->一般不用重启crontab服务,如需重启,可以再执行以下命令
/etc/init.d/crond restart