Skip to content

Instantly share code, notes, and snippets.

@chernjie
Created April 1, 2016 07:54
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 chernjie/2ada173fd03bbd50c970b179e1adb45b to your computer and use it in GitHub Desktop.
Save chernjie/2ada173fd03bbd50c970b179e1adb45b to your computer and use it in GitHub Desktop.
#!/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