linux 自动重启tomcat

一般情况下,下面的代码可以满足:
#!/bin/sh
while :
do
declare hours=$(date --date=`date +%H` | awk '{print $5}')
echo $hours
if [ "$hours" = "22:00:00" -o "$hours" = "04:00:00" -o "$hours" = "10:00:00" -o "$hours" = "16:00:00" ]
then
cd /opt/tomcat01/bin
sleep 10
./shutdown.sh
sleep 30
./startup.sh
sleep 2400
else
sleep 1800
echo $hours
fi
done


但是,有时候,还不管用。只能在加一句强行关闭tomcat

#!/bin/sh
while :
do
declare hours=$(date --date=`date +%H` | awk '{print $5}')
if [ "$hours" = "22:00:00" -o "$hours" = "04:00:00" -o "$hours" = "10:00:00" -o "$hours" = "16:00:00" ]
then
        cd /opt/tomcat01/bin
        sleep 5s
        ./shutdown.sh
        sleep 2m
        pid=`ps -ef|grep java|grep -v grep |awk '{print $2}'`
        if [ -n "$pid" ]
        then
                echo "tomcat is alive.pid=$pid"
                kill -9 $pid
        else
                echo "tomcat is death"
        fi
        sleep 20s
        ./startup.sh
        sleep 1h
else
        sleep 30m
        echo $hours
fi
date
done


猜你喜欢

转载自lzj0470.iteye.com/blog/1885225