Have you ever been frustrated when there are millions of unwanted processes running in a server and you need to kill them all?
And to make matters worse "killall" just doesn't seem to work!!!
I made this little script to solve this issue , you can kill any process with a given string in its name or any processes from a given user
#!/bin/bash
if [ "$1" == "-u" ] ; then
PID=`cat /etc/passwd | grep "$2" | cut -d ":" -f3`
processes=`ps aux | grep "$PID" | egrep -v "PID|ps \-au|killbyname|grep" | awk '{ print $2}'`
echo "############# Killing all processes of user: $2 ############################"
else
echo "############# Killing processes by name: $1 ############################"
processes=`ps aux | grep "$1" | egrep -v "killbyname|grep" | awk '{ print $2}' `
fi
for process in $processes ; do
command=`ps aux | grep $process | egrep -v "grep" | awk '{ print $2 }'`
echo "Killing process: $process"
echo ""
kill -9 $process
done
USAGE:
./killbyname.sh "name"
Will kill any process with "name" in its running path , important to remember that if the process has "name" in any part of its running path it will be killed.
./killbyname.sh -u "username"
Will kill any processes being run by the specified username.
Feel free to improve it!
Nenhum comentário:
Postar um comentário