Created
April 1, 2016 07:54
-
-
Save chernjie/2ada173fd03bbd50c970b179e1adb45b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
_whack_a_mole_log=~/dotfiles/log/whack-a-mole.log | |
_whack_a_mole () { | |
printf $@: | |
while true | |
do | |
i=$(ps aux | grep $@ | grep -ve grep -ve whack-a-mole | awk '{print $2}') | |
test -z $i && continue | |
printf $i, | |
kill $i | |
done | |
} | |
_whack_a_mole_ps_aux () { | |
ps aux | grep whack-a-mole | grep -ve grep -ve $1 | |
} | |
### OPTIONS ### | |
case $1 in | |
'') | |
grep OPTIONS -A100 $0 | |
;; | |
list) | |
_whack_a_mole_ps_aux $1 | |
;; | |
log) | |
tail -f "$_whack_a_mole_log" | |
;; | |
kill) | |
_whack_a_mole_ps_aux $1 | awk '{print $2}' | xargs kill | |
echo >> "$_whack_a_mole_log" | |
;; | |
*) | |
_whack_a_mole $@ >> "$_whack_a_mole_log" & | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment