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