Hello Friends,
I am trying to create a shell script which will check the CPU utilization. I use command
top
to check the %CPU usage. It give s me below output
Cpu states:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS
0 0.31 9.6% 0.0% 6.1% 84.3% 0.0% 0.0% 0.0% 0.0%
1 0.34 13.0% 0.0% 7.1% 80.0% 0.0% 0.0% 0.0% 0.0%
2 0.33 13.8% 0.4% 5.5% 80.4% 0.0% 0.0% 0.0% 0.0%
3 0.33 22.4% 0.0% 5.5% 72.1% 0.0% 0.0% 0.0% 0.0%
4 0.31 18.5% 0.0% 6.3% 75.2% 0.0% 0.0% 0.0% 0.0%
5 0.35 16.7% 0.0% 6.9% 76.4% 0.0% 0.0% 0.0% 0.0%
--- ---- ----- ----- ----- ----- ----- ----- ----- -----
avg 0.33 15.6% 0.0% 6.1% 78.3% 0.0% 0.0% 0.0% 0.0%
Below this output it shows several processes and their CPU utilization.
This output changes after 4-5 seconds.
I am trying to develop a script which will add up a value in last row and 6th column ( IDLE) continuously for one minute and take its average. If this average is less than 20 then send a mail to xyz@info.com with body message "CPU utilization is high on server"
for example in one minute values in last row and 6th column changes in one minute as 78,45,67,78,86 then add up all these values and find its average. If it is less than 20 then send mail.
This script should continuously run in background 24*7.