#!/bin/bash port=$1 tomcat=$2 tomcat_condition_code="$tomcat/bin/tomcat-juli.jar" ${tomcat}/bin/shutdown.sh 2>/dev/null sleep 5 pids=`netstat -tlnp | grep "$port" | awk '{print $7}' | awk -F '/' '{print $1}'` if [ ! $pids ]; then pids=`ps -ef | grep "$tomcat_condition_code" | grep -v grep | awk '{print $2}'` fi for pid in $pids do if [ ${pid} -gt 0 ] 2>/dev/null ; then kill ${pid} sleep 2 times = 0 count=`ps -ax | awk '{ print $1 }' | grep -e "^${pid}$"` while [ ${count} == 1 ] do sleep 1 count=`ps -ax | awk '{ print $1 }' | grep -e "^${pid}$"` if [ ${count} == 0 ] ;then break fi ((times+=1)) if [ ${times} -ge 10 ] ;then kill -9 ${pid} echo "force to stop tomcat" break fi done fi done echo "${tomcat} has been stoped"
./shutdown.sh 8080 /usr/local/apache-tomcat-7.0.70/apache