X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dns323-op.sh;h=f8fac166e701e7c37a512d270b239a03b45ed4b7;hb=844f03ff70febed3f8a500729f7a67c0bf995d35;hp=2aa5c147c1e05d17a1ed85eb493ab40e20b51631;hpb=2b983c5c7336826b764036e3e1478a5a8159248a;p=scripts.git diff --git a/dns323-op.sh b/dns323-op.sh index 2aa5c14..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 } @@ -34,7 +34,8 @@ function authentify_on_dns323 () { echo "Authentifying on ${DNS323_HOSTNAME}." curl -s > /dev/null \ -L http://${DNS323_HOSTNAME}/goform/formLogin \ - -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" || (echo "Failed." >&2 && exit 1) + -d "f_LOGIN_NAME=admin&f_LOGIN_PASSWD=${DNS323_ADMIN_PASSWORD}&f_login_type=0" \ + || (echo "Failed." >&2 && exit 1) already_authentified=1 fi } @@ -94,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