shell 小数比较案例

案例一:

[was@was-rsync ~]$ vi /backall/ita-scripts/monitor/redis-mem.sh    
#!/bin/bash
used_memory_peak_human16390=`ssh [email protected] /data/tools/rediscluster/redis-4/src/redis-cli -h 10.10.130.93 -p password in
fo | grep used_memory_peak_human | awk -F ":" '{print $NF}'| awk -F "G" '{print $1 }'`
sleep 3
used_memory_peak_human16392=`ssh [email protected] /data/tools/rediscluster/redis-4/src/redis-cli -h 10.10.130.93 -p password in
fo | grep used_memory_peak_human | awk -F ":" '{print $NF}'| awk -F "G" '{print $1 }'`
sleep 3
used_memory_peak_human16394=`ssh [email protected] /data/tools/rediscluster/redis-4/src/redis-cli -h 10.10.130.93 -p password in
fo | grep used_memory_peak_human | awk -F ":" '{print $NF}'| awk -F "G" '{print $1 }'`

echo ${used_memory_peak_human16390} | grep -v M > /tmp/used_memory_peak_human.log
echo ${used_memory_peak_human16392} | grep -v M >> /tmp/used_memory_peak_human.log
echo ${used_memory_peak_human16394} | grep -v M >> /tmp/used_memory_peak_human.log

for i in cat /tmp/used_memory_peak_human.log ;do
#if [ ${used_memory_peak_human16394} -gt 3 ];then
if [ `expr ${used_memory_peak_human16394} \> 3` -eq 0 ];then
echo is ok
else
(/usr/bin/uuencode /tmp/used_memory_peak_human.log report.txt;)|/usr/bin/email  -s  "redis used_memory_peak_human is warning" [email protected]

fi
done

 

案例二:

shell的 [ ] 对于数值的判断都是基于整数的,如果碰到小数就无能为力了。google了一把发现用awk的牛人多,不过发现一个兄弟的更加好。

if [ `expr $a \> $b` -eq 0 ];then
    echo $b is bigger
else
    echo $a is bigger
fi

通过expr来进行判断,所以a 和 b 可以是小数。

 

你可能感兴趣的:(shell 小数比较案例)