#!/bin/bash # Filesystem 1024-blocks Used Available Capacity Mounted on # Filesystem Inodes IUsed IFree IUse% Mounted on # [1008M 217M 741M 23%] [128K 24K 105K 19%] ((REDdisk = 89)) ((YELLOWdisk = 79)) ((LIGHTBLUEdisk = 69)) ((WHITEdisk = 10)) ((REDinode = 89)) ((YELLOWinode = 79)) ((LIGHTBLUEinode = 69)) ((WHITEinode = 0)) ((short=0)) ansiStop="\033[0m" redAnsi="\033[1;31m" yellowAnsi="\033[1;33m" lightblueAnsi="\033[1;36m" whiteAnsi="\033[1;37m" printHeader='Y' while [[ "X$1" != "X" ]] do if [[ 'help' == "$1" ]] then echo "Usage: $0 [over] [hint] [noheader]" echo " over -- display serious cases" echo " hint -- display interesting cases" echo " noheader -- do not display header" echo " text -- no color" exit fi if [[ 'noheader' == "$1" ]] then printHeader='N' fi if [[ 'over' == "$1" ]] then ((short=1)) fi if [[ 'hint' == "$1" || 'hints' == "$1" ]] then ((short=2)) fi if [[ 'text' == "$1" ]] then ansiStop="" redAnsi="" yellowAnsi="" lightblueAnsi="" whiteAnsi="" fi shift done df -Ph | grep '^/' | grep -v '/dev/sr0' | awk '{print $6}' | while read fs do fsp=$(echo ${fs} | sed 's|/backups/||') space=$(df -Ph ${fs} | tail -1 | awk '{print $2,$3,$4,$5}') set ${space} blocks="$1" used="$2" avail="$3" cap="$4" capn=$(echo ${cap} | sed 's/%//') inodes=$(df -Phi ${fs} | tail -1 | awk '{print $2,$3,$4,$5}') set ${inodes} inds="$1" iused="$2" ifree="$3" iper="$4" if [[ 'X-' == "X${iper}" ]] then iper="0%" fi ipern=$(echo ${iper} | sed 's/%//') # echo "$fsp [$space] [$inodes]" # printf "%40s %6s %6s %6s %5s %6s %6s %6s %6s\n" ${fsp} ${blocks} ${used} ${avail} ${cap} ${inds} ${iused} ${ifree} ${iper} if ((0 == short)) || (( (1 == short) && ( (YELLOWdisk < capn) || (YELLOWinode < ipern) ) )) || (( (2 == short) && ( (WHITEdisk > capn) || (WHITEinode > ipern) || (LIGHTBLUEdisk < capn) || (LIGHTBLUEinode < ipern) ) )) then if [[ 'Y' == ${printHeader} ]] then printHeader='N' printf "%40s %6s %6s %6s %5s %6s %6s %6s %6s\n" 'Filesystem' 'Blocks' 'Used' 'Free' 'Cap' 'Inodes' 'IUsed' 'IFree' 'IUse%' fi printf "%40s %6s %6s %6s " ${fsp} ${blocks} ${used} ${avail} if ((REDdisk < capn)) then printf "${redAnsi}%5s${ansiStop} " ${cap} else if ((YELLOWdisk < capn)) then printf "${yellowAnsi}%5s${ansiStop} " ${cap} else if ((LIGHTBLUEdisk < capn)) then printf "${lightblueAnsi}%5s${ansiStop} " ${cap} else if ((WHITEdisk > capn)) then printf "${whiteAnsi}%5s${ansiStop} " ${cap} else printf "%5s " ${cap} fi fi fi fi printf "%6s %6s %6s " ${inds} ${iused} ${ifree} if ((REDinode < ipern)) then printf "${redAnsi}%5s${ansiStop} " ${iper} else if ((YELLOWinode < ipern)) then printf "${yellowAnsi}%5s${ansiStop} " ${iper} else if ((LIGHTBLUEinode < ipern)) then printf "${lightblueAnsi}%5s${ansiStop} " ${iper} else if ((WHITEinode > ipern)) then printf "${whiteAnsi}%5s${ansiStop} " ${iper} else printf "%5s " ${iper} fi fi fi fi printf "\n" fi done