From 66118b17e4383da811cbb42a1bb42822a09757dc Mon Sep 17 00:00:00 2001 From: Keith Nash Date: Sun, 19 Mar 2017 10:52:41 -0500 Subject: [PATCH] Consistent if and do code formatting --- zpool_report.sh | 145 +++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 75 deletions(-) diff --git a/zpool_report.sh b/zpool_report.sh index 0062085..b9a33b6 100644 --- a/zpool_report.sh +++ b/zpool_report.sh @@ -38,74 +38,70 @@ echo "
" >> ${logfile}
   echo "+--------------+--------+------+------+------+----+--------+------+-----+"
 ) >> ${logfile}
 
-for pool in $pools
-  do
-    status="$(zpool list -H -o health "$pool")"
-    errors="$(zpool status "$pool" | grep -E "(ONLINE|DEGRADED|FAULTED|UNAVAIL|REMOVED)[ \t]+[0-9]+")"
-    readErrors=0
-    for err in $(echo "$errors" | awk '{print $3}')
-      do
-        if echo "$err" | grep -E -q "[^0-9]+"; then
-          readErrors=1000
-          break
-        fi
-        readErrors=$((readErrors + err))
-      done
-    writeErrors=0
-    for err in $(echo "$errors" | awk '{print $4}')
-      do
-        if echo "$err" | grep -E -q "[^0-9]+"; then
-          writeErrors=1000
-          break
-        fi
-        writeErrors=$((writeErrors + err))
-      done
-    cksumErrors=0
-    for err in $(echo "$errors" | awk '{print $5}')
-      do
-        if echo "$err" | grep -E -q "[^0-9]+"; then
-          cksumErrors=1000
-          break
-        fi
-        cksumErrors=$((cksumErrors + err))
-      done
-    if [ "$readErrors" -gt 999 ]; then readErrors=">1K"; fi
-    if [ "$writeErrors" -gt 999 ]; then writeErrors=">1K"; fi
-    if [ "$cksumErrors" -gt 999 ]; then cksumErrors=">1K"; fi
-    used="$(zpool list -H -p -o capacity "$pool")"
-    scrubRepBytes="N/A"
-    scrubErrors="N/A"
-    scrubAge="N/A"
-    if [ "$(zpool status "$pool" | grep "scan" | awk '{print $2}')" = "scrub" ]; then
-      scrubRepBytes="$(zpool status "$pool" | grep "scan" | awk '{print $4}')"
-      scrubErrors="$(zpool status "$pool" | grep "scan" | awk '{print $8}')"
-      scrubDate="$(zpool status "$pool" | grep "scan" | awk '{print $15"-"$12"-"$13"_"$14}')"
-      scrubTS="$(date -j -f "%Y-%b-%e_%H:%M:%S" "$scrubDate" "+%s")"
-      currentTS="$(date "+%s")"
-      scrubAge=$((((currentTS - scrubTS) + 43200) / 86400))
+for pool in $pools; do
+  status="$(zpool list -H -o health "$pool")"
+  errors="$(zpool status "$pool" | grep -E "(ONLINE|DEGRADED|FAULTED|UNAVAIL|REMOVED)[ \t]+[0-9]+")"
+  readErrors=0
+  for err in $(echo "$errors" | awk '{print $3}'); do
+    if echo "$err" | grep -E -q "[^0-9]+"; then
+      readErrors=1000
+      break
     fi
-    if [ "$status" = "FAULTED" ] \
-    || [ "$used" -gt "$usedCrit" ] \
-    || ( [ "$scrubErrors" != "N/A" ] && [ "$scrubErrors" != "0" ] )
-    then
-      symbol="$critSymbol"
-    elif [ "$status" != "ONLINE" ] \
-    || [ "$readErrors" != "0" ] \
-    || [ "$writeErrors" != "0" ] \
-    || [ "$cksumErrors" != "0" ] \
-    || [ "$used" -gt "$usedWarn" ] \
-    || [ "$scrubRepBytes" != "0" ] \
-    || [ "$(echo "$scrubAge" | awk '{print int($1)}')" -gt "$scrubAgeWarn" ]
-    then
-      symbol="$warnSymbol"
-    else
-      symbol=" "
+    readErrors=$((readErrors + err))
+  done
+  writeErrors=0
+  for err in $(echo "$errors" | awk '{print $4}'); do
+    if echo "$err" | grep -E -q "[^0-9]+"; then
+      writeErrors=1000
+      break
     fi
-    (
-    printf "|%-12s %1s|%-8s|%6s|%6s|%6s|%3s%%|%8s|%6s|%5s|\n" \
-    "$pool" "$symbol" "$status" "$readErrors" "$writeErrors" "$cksumErrors" \
-    "$used" "$scrubRepBytes" "$scrubErrors" "$scrubAge"
-    ) >> ${logfile}
+    writeErrors=$((writeErrors + err))
+  done
+  cksumErrors=0
+  for err in $(echo "$errors" | awk '{print $5}'); do
+    if echo "$err" | grep -E -q "[^0-9]+"; then
+      cksumErrors=1000
+      break
+    fi
+    cksumErrors=$((cksumErrors + err))
+  done
+  if [ "$readErrors" -gt 999 ]; then readErrors=">1K"; fi
+  if [ "$writeErrors" -gt 999 ]; then writeErrors=">1K"; fi
+  if [ "$cksumErrors" -gt 999 ]; then cksumErrors=">1K"; fi
+  used="$(zpool list -H -p -o capacity "$pool")"
+  scrubRepBytes="N/A"
+  scrubErrors="N/A"
+  scrubAge="N/A"
+  if [ "$(zpool status "$pool" | grep "scan" | awk '{print $2}')" = "scrub" ]; then
+    scrubRepBytes="$(zpool status "$pool" | grep "scan" | awk '{print $4}')"
+    scrubErrors="$(zpool status "$pool" | grep "scan" | awk '{print $8}')"
+    scrubDate="$(zpool status "$pool" | grep "scan" | awk '{print $15"-"$12"-"$13"_"$14}')"
+    scrubTS="$(date -j -f "%Y-%b-%e_%H:%M:%S" "$scrubDate" "+%s")"
+    currentTS="$(date "+%s")"
+    scrubAge=$((((currentTS - scrubTS) + 43200) / 86400))
+  fi
+  if [ "$status" = "FAULTED" ] \
+  || [ "$used" -gt "$usedCrit" ] \
+  || ( [ "$scrubErrors" != "N/A" ] && [ "$scrubErrors" != "0" ] )
+  then
+    symbol="$critSymbol"
+  elif [ "$status" != "ONLINE" ] \
+  || [ "$readErrors" != "0" ] \
+  || [ "$writeErrors" != "0" ] \
+  || [ "$cksumErrors" != "0" ] \
+  || [ "$used" -gt "$usedWarn" ] \
+  || [ "$scrubRepBytes" != "0" ] \
+  || [ "$(echo "$scrubAge" | awk '{print int($1)}')" -gt "$scrubAgeWarn" ]
+  then
+    symbol="$warnSymbol"
+  else
+    symbol=" "
+  fi
+  (
+  printf "|%-12s %1s|%-8s|%6s|%6s|%6s|%3s%%|%8s|%6s|%5s|\n" \
+  "$pool" "$symbol" "$status" "$readErrors" "$writeErrors" "$cksumErrors" \
+  "$used" "$scrubRepBytes" "$scrubErrors" "$scrubAge"
+  ) >> ${logfile}
   done
 
 (
@@ -113,15 +109,14 @@ for pool in $pools
 ) >> ${logfile}
 
 ###### for each pool ######
-for pool in $pools
-  do
-    (
-    echo ""
-    echo "########## ZPool status report for ${pool} ##########"
-    echo ""
-    zpool status -v "$pool"
-    ) >> ${logfile}
-  done
+for pool in $pools; do
+  (
+  echo ""
+  echo "########## ZPool status report for ${pool} ##########"
+  echo ""
+  zpool status -v "$pool"
+  ) >> ${logfile}
+done
 
 echo "
" >> ${logfile}