shell脚本启动应用,自动获得pid删除进程应用

start.sh脚本

#!/bin/bash

nohup /export/app/jdk/jdk1.7.0_67/bin/java -jar /export/app/www.100000metaq/click_log_kafka_consumer.jar > click_log_kafka_consumer.log 2>&1  &

proc_name="click_log_kafka_consumer.jar"

name_suffixx="\>"

proc_id=`ps -ef|grep -i ${proc_name}${name_suffixx}|grep -v "grep"|awk '{print $2}'`

echo ${proc_name}" pid:"

echo ${proc_id[@]}

--------------------------------------------------------------------------

stop.sh脚本

#!/bin/bash
proc_name="click_log_kafka_consumer.jar"
name_suffixx="\>"
proc_id=`ps -ef|grep -i ${proc_name}${name_suffixx}|grep -v "grep"|awk '{print $2}'`
if [[ -z $proc_id ]];then
    echo "The task is not running ! "
else
     echo ${proc_name}" pid:"
     echo ${proc_id[@]}
     echo "------kill the task!------"
     for id in ${proc_id[*]}
     do
       echo ${id}
       thread=`ps -mp ${id}|wc -l`
       echo "threads number: "${thread}
       kill -9 ${id}
       
       if [ $? -eq 0 ];then
          
            echo "task is killed ..."
       else
            echo "kill task failed "
       fi
     done
fi

你可能感兴趣的:(shell脚本启动应用,自动获得pid删除进程应用)