1 # this script checks average cpu load for last 5 minutes
2 # since this server has only one core the system will be fully #utilized when average cpu load values reach 1.00.
3 # This script will send warning alert if value exceedes 0.80 so that action can be taken promptly.
4 # finally it will display the top 10 users and their processes #with highest cpu utilization.
5 #!/bin/bash
6 up=$(uptime | awk '{ print$10 }'| sed 's/,$//')
7 if($up -gt 0.80];
8 echo "============================================" >> /tmp/load
9 ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/load
10 mail -s "warning alert on QA server , CPU load exceedes the warning threshold" priyank.dewli@qpay.com.qa issuing-alerts@nexxuspg.com < /tmp/load
11 exit
=======================
error after executing the script
line 12: syntax error: unexpected end of file
最佳答案
检查这一行:
if($up -gt 0.80];
我觉得你想要
if (( $(bc <<< "$up > 0.8") ))
then
echo ...
ps ...
mail ...
fi
关于linux - linux 中的 monitor-cpu 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35153870/