Created
August 11, 2015 04:34
-
-
Save kjbrum/ced851437f3fb8190299 to your computer and use it in GitHub Desktop.
A small bash script to search and kill processes
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 | |
if [ -z "$1" ]; then | |
echo "You need to supply a search string..." | |
else | |
processes=$(ps aux | grep $1 -i | awk -F ' ' '{print $2}' | xargs) | |
echo "Processes: "$processes | |
while true; do | |
read -ep "Are you sure you want kill all '$1' processes? [y/N] " yesno | |
case $yesno in | |
[Yy]* ) | |
echo 'Killing processes...' | |
for i in $processes; do kill $i; done | |
echo "Processes Killed: " $processes | |
break;; | |
* ) | |
echo "Skipped killing processes..." | |
break;; | |
esac | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more better:
processes=$(ps aux | grep $1 -i|grep -v grep | awk -F ' ' '{print $2}' | xargs)