日期:2014-05-16  浏览次数:20717 次

linux下自动重启tomcat
假设脚本存为launch.sh,端口为8080

#!/bin/sh
if [ $# -le 0 ];then
        echo 'eg:./launch.sh 8080'
        exit 0
fi

path=$(pwd)
port=$1

num=100
while [ $num -gt 0 ]
do
        echo $num
        ps ax|grep $port|grep -v grep|grep -v ${0}|awk '{print $1}' -> tmp.txt
        for pid in $(cat tmp.txt)
        do
        {
                echo "kill -9 $pid"
                kill -9 $pid 
        }
        done
        rm -rf tmp.txt
        $path/./startup.sh
        sleep 300
        $((num--))
done