Created
August 17, 2012 16:00
-
-
Save benshimmin/3380146 to your computer and use it in GitHub Desktop.
Search for a process called {searchterm} and kill it if it exists
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
#!/bin/bash | |
# The secret is to use the word boundary in the regex so it doesn't | |
# return the grep process too. | |
# Then use awk to extricate the second column of the match. | |
# Capture that as $PID and kill -9 it (if it exists). | |
PID=`ps auxww | grep -E "\\bsearchterm" | awk '{ print $2 }'` | |
if [ $PID ]; then | |
kill -9 $PID | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment