美文网首页Shell
shell脚本查找并杀死jar包进程

shell脚本查找并杀死jar包进程

作者: WebGiser | 来源:发表于2020-10-24 16:22 被阅读0次

环境:centos7.2、jdk1.8
shell脚本根据用户输入的jar包名称自动查找到pid进程,将其杀死。

1、restart_jar.sh脚本代码:

#!/bin/bash

echo "请输入jar包名称:"
read jar_name

PID=$(ps -ef | grep ${jar_name} | grep -v grep | awk '{print $2}')

if [ ! $PID ]; then
    echo "process ${jar_name} not exit"
    exit
else
    echo "process id: $PID"
fi

kill -9 ${PID}

if [ $? -eq 0 ]; then
    echo "kill ${jar_name} success"
else
    echo "kill ${jar_name} fail"
fi

2、执行脚本

sh  restart_jar.sh

相关文章

网友评论

    本文标题:shell脚本查找并杀死jar包进程

    本文链接:https://www.haomeiwen.com/subject/abtwmktx.html