#!/bin/bash # diskhogs--Disk quota analysis tool for Unix; assumes all user # accounts are >= UID 100. Emails message to each violating user # and reports a summary to the screen. setglobal MAXDISKUSAGE = '1' setglobal violators = ""/tmp/diskhogs0.$Pid"" trap "$[which rm] -f $violators" 0 for name in [$[cut -d: -f1,3 /etc/passwd | awk -F: '$2 > 99 { print $1 }]] { echo -n "$name " # You might need to modify the following list of directories to match # the layout of your disk. Most likely change: /Users to /home find / /usr /var /Users -xdev -user $name -type f -ls | \ awk '{ sum += $7 } END { print sum / (1024*1024) }' } | awk "\$2 > $MAXDISKUSAGE { print \$0 }" > $violators if test ! -s $violators { echo "No users exceed the disk quota of $(MAXDISKUSAGE)MB" cat $violators exit 0 } while read account usage { cat << """ | fmt | mail -s "Warning: $account Exceeds Quota" $account Your disk usage is $(usage)MB, but you have been allocated only $(MAXDISKUSAGE)MB. This means that you need to either delete some of your files, compress your files (see 'gzip' or 'bzip2' for powerful and easy-to-use compression programs), or talk with us about increasing your disk allocation. Thanks for your cooperation in this matter. Dave Taylor @ x554 """ fmt | mail -s "Warning: $account Exceeds Quota" $account Your disk usage is ${usage}MB, but you have been allocated only ${MAXDISKUSAGE}MB. This means that you need to either delete some of your files, compress your files (see 'gzip' or 'bzip2' for powerful and easy-to-use compression programs), or talk with us about increasing your disk allocation. Thanks for your cooperation in this matter. Dave Taylor @ x554 EOF echo "Account $account has $usage MB of disk space. User notified." } < $violators exit 0