Created
June 7, 2012 20:26
-
-
Save re5et/2891341 to your computer and use it in GitHub Desktop.
grepkill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment