#!/usr/local/bin/bash # Copyright (C) 1995, Mats Kindahl. All rights reserved. # This program is in the public domain, you can redistribute # it and/or modify it as long as this copyright notice is # kept. # # This software is delivered as-is. There is NO WARRANTY, neither # implicit nor explicit, for this code. # # E-mail: matkin@docs.uu.se # # Script to count the amount of "garbage" in each users # directory. Will then generate bourne shell code which will send a # nice little mail to each of the users in question. # If you supply a directory, it is assumed to contain accounts for # which garbage should be counted. # Usage: count-garbage [ ] # is the directory where all the users directory are # located, default is /home/kay/docs. count-garbage () { ls -s $(find $1 '(' -name '*~' -o -name '.*~' -o -name core ')' \ -print 2>/dev/null) | cut -c-4 | perl -ne '$n += $_; print $n if eof;' } # Usage: get-name # Function that will get the real first name of . function get-name () { ypmatch ${1} passwd | { IFS=: read user pswd uid gid gcos dir shell set $gcos echo $1 } } # Main program cd ${1:-${HOME}/..} # Default location to look for user in * do garbage=$(count-garbage ${user}) name=$(get-name ${user}) if [ "$garbage" -ge 200 ] then echo '# --------------------------------------------------------------' echo mail -s \"${garbage} kbytes of garbage\" ${user} "<