Added the percentage of disk usage.
authorFrancois Fleuret <francois@fleuret.org>
Tue, 22 Nov 2011 20:07:46 +0000 (21:07 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Tue, 22 Nov 2011 20:07:46 +0000 (21:07 +0100)
dns323-op.sh

index 614eb21..f8fac16 100755 (executable)
@@ -23,9 +23,9 @@
 set -e
 
 function rm_temp () {
-    if [[ ${TEMP} ]]; then
-        rm ${TEMP}
-        unset TEMP
+    if [[ ${TMP} ]]; then
+        rm ${TMP}
+        unset TMP
     fi
 }
 
@@ -95,18 +95,36 @@ if [[ ${DNS323_HOSTNAME} ]] && \
                 # If you think what follows is fugly, please have a
                 # look at the DNS323's web app HTML
 
-                TEMP=$(mktemp /tmp/status.XXXXXX)
+                TMP=$(mktemp /tmp/status.XXXXXX)
 
                 curl -s \
                     -L http://${DNS323_HOSTNAME}/goform/adv_status \
-                    -d "" > ${TEMP}
+                    -d "" > ${TMP}
 
-                cat ${TEMP} | \
+                cat ${TMP} | \
                     html2text | \
                     grep "\(Sync Time Remaining\|Volume Name\|Volume Type\|Total Hard Drive Capacity\|Used Space\|Unused Space\)": | \
-                    sed -e "s/^[ \t]*//"
-
-                grep "var temper" ${TEMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature:                \1F \/ \2C/"
+                    sed -e "s/^[ \t]*//" | while read line; do
+                    label=$(echo ${line} | sed -e "s/:.*$//")
+                    value=$(echo ${line} | sed -e "s/^[^0-9]*\([0-9]*\).*$/\1/")
+                    comment=""
+                    case ${label} in
+                        "Total Hard Drive Capacity")
+                            total=${value}
+                            ;;
+                        "Used Space")
+                            comment="($(((value*100)/total))%)"
+                            ;;
+                        "Unused Space")
+                            comment="($(((value*100)/total))%)"
+                            ;;
+                        *)
+                            ;;
+                    esac
+                    echo "${line} ${comment}"
+                done
+
+                grep "var temper" ${TMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature:                \1F \/ \2C/"
 
                 rm_temp