![]() ![]() #with top command time format is hh:mm.ss, so truncare seconds in c2 ![]() # Decode the top CPU time format hh:mm.ss. ![]() PID=$(top -bcSH -n 1 | grep $PROCESS_TOCHECK | sort -k $SORTBY -r | head -n 1 | awk '') #retrive pid with top command order by SORTBY #iterate for each process to check in list KILLLIST=("/usr/sbin/apache2" "/usr/bin/php5-cgi") #define a processes command name to check #max execution time for CPU percentage > MAX_CPU (in seconds 7200s=2h) NOTE: Here is my repo on Github: Essential part of script (a code abstract for top command): #!/usr/bin/env bash In the end, the script sends an email if some processes were killed.There's a dry run mode too, to check but not kill.You can use a ps or top for check processes.You can set XX, YY, ZZ in the top of the file.I have created a script, kill-process, that kills some processes listed in an array, if CPU usage is greater than XX% for YY seconds or kill processes that's running more than ZZ seconds. ![]()
0 Comments
Leave a Reply. |