ps -ef|grep xxx.jar|grep -v grep|awk ‘{print $2}‘|xargs kill -9解析

#!/bin/sh
# ps -ef|grep erp-api.jar 查询erp-api.jar进程
# grep -v 不包含
# ps -ef|grep erp-api.jar|grep -v grep|awk ‘{print $2}’ 获取第二个参数
# xargs 将前面获取到的进程号通过空格分割,传递给kill -9,杀死所有进程
ps -ef | grep erp-api.jar | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep erp-bills-service.jar | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep erp-basicdata-service.jar | grep -v grep | awk '{print $2}' | xargs kill -9
nohup java -jar erp-api.jar > /home/app/erp-api.out 2>&1 &
nohup java -jar erp-bills-service.jar > /home/app/erp-bills.out 2>&1 &
nohup java -jar erp-basicdata-service.jar > /home/app/erp-basicdata.out 2>&1 &

# echo $! 打印进程号到某个文件
echo $! > erp-api.pid
echo $! > erp-bills-service.pid
echo $! > erp-basicdata-service.pid

你可能感兴趣的:(java,shell,linux)