From: Francois Fleuret Date: Tue, 22 Nov 2011 20:07:46 +0000 (+0100) Subject: Added the percentage of disk usage. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=844f03ff70febed3f8a500729f7a67c0bf995d35;p=scripts.git Added the percentage of disk usage. --- diff --git a/dns323-op.sh b/dns323-op.sh index 614eb21..f8fac16 100755 --- a/dns323-op.sh +++ b/dns323-op.sh @@ -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