一个简单实现的快速杀进程脚本

本脚本实现的目的是替换掉 ps aux | grep -i xxx 然后再 kill -9 xxxpid ...

 

#!/bin/bash

app_name=$1
echo "app_name is $app_name"
pid=$(ps aux | grep -i $app_name | grep -v "grep -i" | grep -v "killapp" | awk '{print $2}')
if [[ "x$pid" = "x" ]]
then
  echo "$app_name process not existed.."
  exit 1
fi
echo "pid is $pid"
kill -9 $pid
echo "$app_name has been killed!”


使用举例:

$ ./killapp goagent
app_name is goagent
pid is 1292
goagent has been killed!

$ ./killapp goagent
app_name is goagent

goagent process not existed..

 

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