cpu= $(mpstat | awk '$12 ~ /[0-9.]+/ { printf("%d%%",100 - $12) }' | cut -d. -f1)
How to refrain the output in numeric?
It's failing while comparing %
string with numeric.
cpu= $(mpstat | awk '$12 ~ /[0-9.]+/ { printf("%d%%",100 - $12) }' | cut -d. -f1)
How to refrain the output in numeric?
It's failing while comparing %
string with numeric.
Don't put the %
in the awk
output. Add it when you're creating the email. You can also use awk's int()
function to remove the fraction from the output, rather than piping to cut
.
Also, make sure you don't have any spaces around the =
in the cpu
assignment.
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