I'm trying to run a command every 10 minutes while usage of CPU is under 80%. I'm not used to bash scripting. I've found a way to get the total use of CPU ``top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'` and then I want to compare with a maximum of 80%. But I'm not sure why I cannot compare both. Here the script:
#!/bin/bash
MAX=80
CPU=`top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`
while true
do
if $CPU < $MAX
then
echo $CPU # This is an example
CPU=`top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`
sleep 10m
fi
done
The script fails because interpret the numbers as a command... (cannot open 80: No such file
)
Why I cannot compre $MAX
and $CPU
? and how would you tackle this?
Thanks in advance.