Skip to content

Instantly share code, notes, and snippets.

@re5et
Created May 16, 2013 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save re5et/5588460 to your computer and use it in GitHub Desktop.
Save re5et/5588460 to your computer and use it in GitHub Desktop.
#! /bin/bash
case "$1" in
'' | -h | --help)
NOARGS=1 ;;
-d)
DRY=1; FIND=$2 ;;
*)
DRY=0; FIND=$1 ;;
esac
if [[ $NOARGS -eq "1" || -z $FIND ]]
then
echo '
usage: grepkill (-d for dry run) [thing_to_find_and_kill]'
exit 0
fi
COMMAND="ps -eo pid,args | grep -v grep | grep $FIND"
echo "
KILLING:
"
echo $COMMAND | sh
echo "
"
PIDS=$(echo $COMMAND | sh | awk '{ print $1 }')
echo kill -9 $PIDS
if [ $DRY -eq "0" ]
then
echo kill -9 $PIDS | sh
else
echo 'dry run, nothing killed'
fi
exit 0
@TrevorBramble
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment