cpu= $(mpstat | awk '$12 ~ /[0-9.]+/ { printf("%d%%",100 - $12) }' | cut -d. -f1)
如何限制数字输出?
将%
字符串与数字进行比较失败。
答案 0 :(得分:1)
请勿将%
放在awk
输出中。创建电子邮件时将其添加。您还可以使用awk的int()
函数从输出中除去分数,而不是通过管道传递到cut
。
还要确保=
分配中cpu
周围没有空格。
cpu=$(mpstat | awk '$12 ~ /[0-9.]+/ {print int(100 - $12) }')
if (( $cpu > 5 ))
then mail -s "CPU Utilization monitoring" "xxx@yyy.com" <<EOF
CPU Utilization is exceeded in Ec2-user Server.
Current use is $cpu%.
EOF
fi