Last active
December 12, 2015 04:18
-
-
Save antsankov/4712906 to your computer and use it in GitHub Desktop.
Process Killer (Helpful for your server) So I was doing some research and I found this script to use for your server, I have tested it out and tweaked it on my own machine, so if you are interested contact me so I can start making the tweaks so it is optimized for the retrograde server. Regards, Alex Tsankov
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 | |
##Note: will kill the top-most process if the $CPU_LOAD is greater than the $CPU_THRESHOLD. | |
#################### FOR TEST PURPOSES ONLY STILL NEEDS TO BE TWEAKED!!!################# | |
echo | |
echo checking for run-away process ... | |
CPU_LOAD=$(uptime | cut -d"," -f4 | cut -d":" -f2 | cut -d" " -f2 | sed -e "s/\.//g") | |
CPU_THRESHOLD=75 # This needs to be customized for the server so it knows when to start killing programs. | |
PROCESS=$(ps aux r) | |
TOPPROCESS=$(ps -eo pid -eo pcpu -eo command | sort -k 2 -r | grep -v PID | head -n 1) | |
if [ $CPU_LOAD -gt $CPU_THRESHOLD ] ; then | |
kill -9 $TOPPROCESS | |
echo system overloading! | |
echo Top-most process killed $TOPPROCESS | |
echo load average is at $CPU_LOAD | |
echo | |
echo Active processes... | |
ps aux r | |
else | |
echo | |
echo no run-aways. | |
echo load average is at $CPU_LOAD | |
echo | |
echo Active processes... | |
ps aux r | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment