From 00a6a016d5235de4cbde26cb40db71119967d3c7 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Fri, 9 Oct 2015 09:42:59 -0700 Subject: [PATCH] Avoid division operation in shell When the data returned from 'rabbitmqctl list_queues' grows a lot and awk sums up all the rows especially for memory calculation it returns the sum in scientific notation (example from bug was .15997e+09), later when we want to calculate the memory in MB instead of bytes, the bash division does not like this string. We can just avoid the situation by doing the division into MB in awk itself. Since we don't need the memory in bytes anyway. Closes-Bug: #1503331 Change-Id: I38d25406b84d0f70ed62101d5fb5ba108bcab8bd --- files/fuel-ha-utils/ocf/rabbitmq | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/fuel-ha-utils/ocf/rabbitmq b/files/fuel-ha-utils/ocf/rabbitmq index 11275796b1..ce53d46880 100755 --- a/files/fuel-ha-utils/ocf/rabbitmq +++ b/files/fuel-ha-utils/ocf/rabbitmq @@ -1270,8 +1270,7 @@ get_monitor() { elif [ -n "${queues}" ]; then local q_c=`echo -e "${queues}" | wc -l` - local m_b=`echo -e "${queues}" | awk -v sum=0 '{sum+=$1} END {print sum}'` - local mem=$(( $m_b / 1048576 )) + local mem=`echo -e "${queues}" | awk -v sum=0 '{sum+=$1} END {print (sum/1048576)}'` local mes=`echo -e "${queues}" | awk -v sum=0 '{sum+=$2} END {print sum}'` local c_u=`echo -e "${queues}" | awk -v sum=0 -v cnt=${q_c} '{sum+=$3} END {print (sum+1)/(cnt+1)}'` local status=`echo $(su_rabbit_cmd "${OCF_RESKEY_ctl} -q status")`