#!/bin/sh
# Olivier Masse, 2005/01/19
#
# This script helps identify CPU hogs on a server. It can take a while
# before a hog is identified, as a potential hog is roughly defined by this:
# - a process which has totaled more than a day of CPU time
# - a process that takes over 50% of the CPU 
# This isn't perfect, so any suggestions on doing better are welcome.
#
# This script can be run from cron to get an e-mail if something fishy is
# going on.
#
#

export UNIX95=1
ps -eo pid,time,pcpu,args | tail +2 | grep -E '\-[0-9][0-9]:[0-9][0-9]:[0-9][0-9]' | while read pid time pcpu cmd
do
	if [ "$pcpu" -gt 50 ]
	then
		echo "Potential Hog: CPU_util=$pcpu, CPU_time=$time, pid=$pid, process='$cmd'"
	fi
done


