Shell Script to send alert on HighCPU Usage on Solaris

Find below a sample script which you can use to send a mail when the there is a High CPU.
I have tested it on Solaris. The server name is TestServer. Feel free to use it in your environment and to share any thoughts.

pid=`/usr/ucb/ps -auxwww | grep TestServer | tr -s ‘ ‘ | cut -d ” ” -f 2 | sed ‘2,$ d’`

prstat -L -p $pid 1 1 > prstat.trace

for x in `sed ‘1d;$d’ prstat.trace | tr -s ‘ ‘ | cut -d ” ” -f 10`
do

a=`echo $x | tr -d ‘%’`
tHold=2.0

res=`expr $a \> $tHold`

if [ $res -eq 1 ]
then
echo “High CPU!! $a % “
fi

done

Leave a Reply