我正在测试一个变量是否大于另一个变量。无论值是什么,if 评估都会获得相同的值。
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 }
即使这些值并没有真正评估为真,我也得到了这个输出。
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
我已经尝试了多种方法,但无法使其正常工作。有任何想法吗?