#!/bin/bash declare -A dfrow out declare -a order array declare prog=${0##*/} QUIET=false DEBUG=false Usage() { cat <<-EOUsage Usage: $prog [-h] [-q] [] []... Options: -q Quiet -d Debug this (by openning xterm windows... look at script) -h Show this help EOUsage } tsize() { local U V=(K M G T P E) W=$(( $1 > 64#3________ ? 5 : $1 > 64#f______ ? 4 : $1>64#_____ ? 3 : $1 > 64#3___ ? 2 : $1 > 1023 ? 1 : 0 )) (( W>4 ? W-- : 0 )) && V=("${V[@]:1}") && set -- $(($1 /1024)) "$2" U=000$(( 1000*$1 / 1024 ** W )) printf -v "$2" %.2f%s ${U::-3}.${U: -3} "${V[W]}" } percent(){ local P=000$(( $1 * 100000 / $2 )) printf -v "$3" %.2f%% "${P::-3}"."${P: -3}" } addOut() { local oline typ="$1" shift printf -v oline '%-25s (%9s %9s) %9s %9s %9s %9s %s\n' "$@" [ -v "out[$typ]" ] || order+=("$typ") out[$typ]+="$oline" } printRow() { local htot rtot huse hfree prct pres oline tot=$(( dfrow[used] + dfrow[available] )) res=$(( dfrow[blocks] - tot )) tsize $tot htot tsize "${dfrow[blocks]}" rtot tsize "${dfrow[used]}" huse tsize "${dfrow[available]}" hfree percent "${dfrow[used]}" "$tot" prct percent "$res" "${dfrow[blocks]}" pres addOut "${dfrow[type]}" "${dfrow[filesystem]//*\/mapper\//dm--}" "$rtot"\ "$pres" "$htot" "$huse" "$hfree" "$prct" "${dfrow[mounted]}" } debug() { exec {log}<> >(:) xterm -geom 146x32+140+40 -T MPLog -S00/$log & XTPid=$! echo >&$log $ printf >&$log '\e[20h%s -- %s\n' "$0" "$*" trap 'kill '"${XTPid}"';exit 0;' 0 1 2 3 6 15 BASH_XTRACEFD=$log DEBUG=true set -x } while getopts "dhq" opt;do case $opt in h ) Usage; exit 0 ;; d ) debug "$*" ;; q ) QUIET=true ;; * ) echo >&2 "$prog ERROR: opt: '$opt' ??"; usage; exit 2 ;; esac done shift $((OPTIND-1)) [ -z "$1" ] && { # Sort filesystems by path level, then alphapetical order mapfile -t array < <( LANG=C df | sed -ne 's/.*% \//\//;ta;bb;:a;h;s/[^\/]*//g;G;s/\n/ /;p;:b' | LANG=C sort -b | sed 's/\/* //' ) set -- "${array[@]}" } addOut hEaDeR FileSystem Real Reserved Total Used Free PUsed Mount\ Point { read -ru $FDDF -a hline hline=("${hline[@]:0:7}") hline=("${hline[@]#*-}") printf -v hline 'dfrow[%s] ' "${hline[@],,}" read -ra hline <<<"$hline" while read -ru $FDDF "${hline[@]}"; do $DEBUG && declare -p dfrow >&$log case ${dfrow[type]} in *tmpfs ) ;; * ) printRow ;; esac done } {FDDF}< <(LANG=C df -PTk "$@") $QUIET || printf "%s" "${out[${order[0]}]}" for type in "${order[@]:1}";do ! $QUIET && ((${#order[@]}>2)) && printf '### %s ###\n' "${type^^}" printf "%s" "${out[$type]}" done $DEBUG && read -rsn 1