#!/bin/bash function right-aligned() { SPC=$(expr $(tput cols) - ${#1}) for (( j=1; j<=$SPC; j++ )); do echo -n " "; done; echo -n ${1} } function fancy-timer() { for (( i=1; i<=$1; i++ )); do SEC=$(expr ${1} - $(expr ${i} - 1)) SECW="second" if [ "$SEC" -ne "1" ]; then SECW="${SECW}s" fi echo -ne "$(right-aligned "${2} ${SEC} ${SECW}")\r" sleep 1 done; if [ ! -z "${3}" ]; then # Callback ${3} ${1} $(date +'%s') fi } function greyhole_monitor() { Z_GHD=$(greyhole -s); Z_GHS=$(greyhole -S); clear; echo -e "${Z_GHD}\\n"; echo -e "${Z_GHS}\\n"; df -h /home; Z_TIME=${1} if [ ! -z "${2}" ]; then Z_DATE=$(date +'%s') Z_DIFF=$(expr ${Z_DATE} - ${2}) Z_TIME=$(expr ${Z_TIME} - ${Z_DIFF}) fi fancy-timer ${Z_TIME} "Updated in ${Z_DIFF}s on $(date -d"@${Z_DATE}" +'%I:%M:%S%p [%Y/%m/%d]'), next update in" greyhole_monitor } clear echo "Gathering initial information from Greyhole... This may take a while..." greyhole_monitor 25 $(date +'%s')