I am testing if a variable is greater than another variable. The if evaluation is getting the same value no matter what the values are.
COMP(){
avg=$(for avg in $(for file in $(ls /var/log/sa/sa[0123]*); do echo $file; done); do sar -r -f $avg| tail -1; done | awk '{totavg+=$4} END {print (totavg/NR)*5}');
for comp in $(sar -r -f /var/log/sa/sa08 | egrep -v "^$|Average|CPU|used" | awk '{print $5}'); do
if [ `echo $avg` < `echo $comp` ];
then echo 'You have had a spike!';
echo "COMP = $comp";
echo "AVG = $avg";
fi;
done }
I am getting this output even though the values are not really evaluating to true.
You have had a spike!
COMP = 41.20
AVG = 145.438
You have had a spike!
COMP = 41.20
AVG = 145.438
You have had a spike!
COMP = 41.19
AVG = 145.438
You have had a spike!
COMP = 41.24
AVG = 145.438
I have tried this multiple ways but can not get it working. Any ideas?
yep as ingnacio has pointed out