-
-
Save obonyojimmy/7f88a43ac1ce2ddd2f00bd482e00de16 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