-
Notifications
You must be signed in to change notification settings - Fork 1
/
sum_of_cat.sh
executable file
·36 lines (28 loc) · 1.25 KB
/
sum_of_cat.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Ensure file name is provided
if [ "x$1" == "x" ]; then
echo "Error! No file name provided."
echo "USAGE: $0 FILENAME"
exit 1
fi
# Primary sizes only
PGB=$(cat $1 | awk '{print $10}' | grep gb | tr -d 'gb' | tr -d '\r' | paste -sd+ - | bc)
PMB=$(cat $1 | awk '{print $10}' | grep mb | tr -d 'mb' | tr -d '\r' | paste -sd+ - | bc)
PKB=$(cat $1 | awk '{print $10}' | grep kb | tr -d 'kb' | tr -d '\r' | paste -sd+ - | bc)
if [ "x$PGB" == "x" ]; then PGB=1; fi
if [ "x$PMB" == "x" ]; then PMB=1; fi
if [ "x$PKB" == "x" ]; then PKB=1; fi
# All storage (include primary and all replicas)
ALLGB=$(cat $1 | awk '{print $9}' | grep gb | tr -d 'gb' | tr -d '\r' | paste -sd+ - | bc)
ALLMB=$(cat $1 | awk '{print $9}' | grep mb | tr -d 'mb' | tr -d '\r' | paste -sd+ - | bc)
ALLKB=$(cat $1 | awk '{print $9}' | grep kb | tr -d 'kb' | tr -d '\r' | paste -sd+ - | bc)
if [ "x$ALLGB" == "x" ]; then ALLGB=1; fi
if [ "x$ALLMB" == "x" ]; then ALLMB=1; fi
if [ "x$ALLKB" == "x" ]; then ALLKB=1; fi
# Do the math
PRIMARY_EXPR="${PGB}+(${PMB}/1024)+(${PKB}/1024/1024)"
PRIMARY=$(echo ${PRIMARY_EXPR} | bc)
TOTAL_EXPR="${ALLGB}+(${ALLMB}/1024)+(${ALLKB}/1024/1024)"
TOTAL=$(echo ${TOTAL_EXPR} | bc)
# Output
echo "Primary-only: ${PRIMARY} GB --- Total Storage: ${TOTAL} GB"