Disk quota check during user login
Posted: April 9th, 2015 | Author: karol | Filed under: Linux, Storage | No Comments »Our users are often unaware of their home directory disk usage and get surprised where they are over their assigned disk quota and cannot write anymore. The script, that follows, is placed in the system /etc/profile.d directory with the name homequota.sh. It checks disk usage and displays information about disk space available under user’s quota. The script is not very sophisticated and could certainly be improved, however, it does satisfy our needs.
# /etc/profile.d/homequota.sh ### displays message informing about disk space available ### under user home directory quota - Karol M. 03262015 if [ `whoami` != "root" ] ; then UU=`quota -sf /home | awk 'NR==4 {print $1}'` QQ=`quota -sf /home | awk 'NR==4 {print $3}'` UUNIT=`echo $UU | sed 's/[0-9]//g'` QUNIT=`echo $QQ | sed 's/[0-9]//g'` USED=`echo $UU | sed 's/[^0-9]*//g'` LIMIT=`echo $QQ | sed 's/[^0-9]*//g'` if [[ $UUNIT =~ "*" ]] ; then echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING: You are over your home directory disk quota !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " else case "$UUNIT" in K) USED=$(($USED * 1024)) ;; M) USED=$(($USED * 1024 * 1024)) ;; G) USED=$(($USED * 1024 * 1024 * 1024)) ;; esac case "$QUNIT" in K) LIMIT=$(($LIMIT * 1024)) ;; M) LIMIT=$(($LIMIT * 1024 * 1024)) ;; G) LIMIT=$(($LIMIT * 1024 * 1024 * 1024)) ;; esac LEFT=$(($LIMIT - $USED)) LEFT=$((LEFT / 1024 / 1024)) echo " ##################################### There are $LEFT megabytes left under your home directory disk quota ##################################### " fi fi
Leave a Reply