X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dns323-op.sh;h=af7a5ed447bcc6377936c46c9481bd0bff1129ea;hb=0fb8308d2117d02eedcd003721606dea8bb796dc;hp=614eb21a97d2484c987a2c8dcefb3354bb519303;hpb=88cc045a5eecced9d8f71c2a8e0aef67a8d94368;p=scripts.git diff --git a/dns323-op.sh b/dns323-op.sh index 614eb21..af7a5ed 100755 --- a/dns323-op.sh +++ b/dns323-op.sh @@ -22,10 +22,36 @@ set -e +export VT_RESET=$'\e[0m' +export VT_BOLD=$'\e[1m' +export VT_UNDERLINE=$'\e[4m' +export VT_BLINK=$'\e[5m' + +export VT_SET_TITLE=$'\e]0;' +export VT_END_TITLE=$'\007' + +export VT_BLACK_FG=$'\e[30m' +export VT_RED_FG=$'\e[31m' +export VT_GREEN_FG=$'\e[32m' +export VT_YELLOW_FG=$'\e[33m' +export VT_BLUE_FG=$'\e[34m' +export VT_MAGENTA_FG=$'\e[35m' +export VT_CYAN_FG=$'\e[36m' +export VT_WHITE_FG=$'\e[37m' + +export VT_BLACK_BG=$'\e[40m' +export VT_RED_BG=$'\e[41m' +export VT_GREEN_BG=$'\e[42m' +export VT_YELLOW_BG=$'\e[43m' +export VT_BLUE_BG=$'\e[44m' +export VT_MAGENTA_BG=$'\e[45m' +export VT_CYAN_BG=$'\e[46m' +export VT_WHITE_BG=$'\e[47m' + function rm_temp () { - if [[ ${TEMP} ]]; then - rm ${TEMP} - unset TEMP + if [[ ${TMP} ]]; then + rm ${TMP} + unset TMP fi } @@ -95,18 +121,41 @@ 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/") + case ${label} in + "Total Hard Drive Capacity") + total=${value} + ;; + "Used Space") + line="${line} ($(((value*100)/total))%)" + ;; + "Unused Space") + line="${line} ($(((value*100)/total))%)" + ;; + "Sync Time Remaining") + state=$(echo ${line} | sed -e "s/^[^:]*:[^A-Za-z]*//") + if [[ ! "${state}" == "Completed" ]]; then + line="${VT_RED_FG}${VT_BOLD}${line} !!! THIS IS NOT NORMAL !!!${VT_RESET}" + fi + ;; + *) + ;; + esac + echo "${line}" + done + + grep "var temper" ${TMP} | sed -e "s/^.*\"\([0-9]*\):\([0-9]*\)\".*$/Temperature: \1F \/ \2C/" rm_temp