CPU utilization in linux script alert

Hi,

This below script will update you whenever the server load goes beyond 15 with the load and the top 10 process which uses maximum CPU.

#!/bin/bash
SUBJECT="`hostname`server load is high"
TO=user@host.com
uptime > /tmp/load
if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 15 ];
then
echo "============================================" >> /tmp/load
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/load `
mail -s "$SUBJECT" $TO < /tmp/load
exit
fi

Thanks for viewing helpinlinux.com

Leave a Reply

Protected by WP Anti Spam