I'am developing bash script, which enabling/disabling ddos protection from cloudflare. Here is my code:
#!/bin/bash
PERC=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}');
if [[ "$PERC" -gt 50 ]]
then
echo 'high load';
else
echo 'normal load';
fi
I have 2 issues: 1. PERC are always the same result 2. seems like result of PERC variable incorrect, because of error '-bash: [[: 41.8679: syntax error: invalid arithmetic operator (error token is ".8679")'
What's wrong with my code?