Tuesday, June 19, 2012

Kill annoying processes that match a pattern

So, there was a bunch of annoying processes named wit a pattern and I wanted to kill all of them

Here is the script (I know this can be done in a much cleaner way in awk, but I like this way)


#!/bin/sh
P="master(-worker)?"

PS=/bin/ps
SED=/bin/sed
KILL=/bin/kill
GREP=/bin/grep
CUT=/usr/bin/cut

$KILL `$PS ax | $GREP -E $P | $GREP -v grep | $SED -e 's/^\ \+//g' | $CUT -d ' ' -f 1 | $GREP -E '^[[:digit:]]+'`

--
  = ^ . ^ =

No comments:

Post a Comment