欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS下停止Tomcat运行脚本代码

程序员文章站 2023-08-26 11:50:55
代码验证通过,保留,以备后用 #!/bin/sh # # firstly find the process of the tomcat.... tomcat...

代码验证通过,保留,以备后用

#!/bin/sh
#
# firstly find the process of the tomcat....
tomcat_process_str=`ps aux | grep 'java.*tomcat' | 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<=10;a++))
do
 check_str_length=0
 tomcat_process_check_str=`ps aux | grep 'java.*tomcat' | grep -v grep`
 check_str_length=${#tomcat_process_check_str}
# 传递到脚本的参数个数;
 if [ $check_str_length != 0 ]
 then
  kill $tomcat_process_id
  sleep 5
  echo try to kill tomcat once more...
 else
  echo tomcat is already killed
  break
 fi
done
#使用两次grep来去除grep自身进程对于查找结果的干扰是非常有技巧的