In order to monitor the CPU usage in an AIX server I'm using the following script that is executed every 10 mins.
lparstat 2 10 > cpu
usage=$(tail -10 cpu | awk 'BEGIN {sum=0;} {sum+=$4} END{print int(100-sum/10)}')
if [[ $usage -ge 90 ]]; then
# mail the error and cpu file to admin
# displaying this for testing purposes
echo "CPU usage off the charts!!!"
cat cpu
fi
However, in case the CPU usage is above 90% I need to list the top 5 Processes that are using the CPU.
How do I achieve this?