版本二
api-restart_sh
#!/bin/bash
#
# Firstly find the process of the tomcat....
TOMCAT_PROCESS_STR=`ps aux | grep 'java.*server-api' | grep -v grep`
PROCESS_ARRAY=(${TOMCAT_PROCESS_STR// / })
TOMCAT_PROCESS_ID=${PROCESS_ARRAY[1]}
echo $TOMCAT_PROCESS_ID
#
# Secondly send stop tomcat to see if we can kill it
#stoptomcat
sleep 12
#
# Last we'll use kill tomcat process in a looking up loop
for ((a=1;a<=5;a++))
do
CHECK_STR_LENGTH=0
TOMCAT_PROCESS_CHECK_STR=`ps aux | grep 'java.*/mnt/soft/server-api' | grep -v grep`
CHECK_STR_LENGTH=${#TOMCAT_PROCESS_CHECK_STR}
if [ $CHECK_STR_LENGTH != 0 ]
then
kill -9 $TOMCAT_PROCESS_ID
sleep 5
echo Try to kill tomcat once more...
else
echo Tomcat is already killed
break
fi
done