v03i013: Mail users about old files

allbery at ncoast.UUCP allbery at ncoast.UUCP
Mon May 9 23:14:20 AEST 1988


comp.sources.misc: Volume 3, Issue 13
Submitted-By: "A. Nonymous" <rsalz at pineapple.bbn.com>
Archive-Name: core_notice

We run this script weekly.
It will need minor tweaking for other sites, but it's not really
BSD or USG dependent.

	/r$


#To unpack, delete all lines before this and feed to /bin/sh
echo core_notice 1>&2
sed -e 's/^X//' >core_notice <<'END'
X#! /bin/sh
X##
X##  Script to find old core, etc., files and send mail to their owners.
X##  It assumes your find has the "-xdev" option to not cross mount
X##  points.  It would like to use System V "xargs" command, but can
X##  use the BSD "fmt" command as a hack, instead.  Also check the mail
X##  commands, below.
X##
X##  The file core_errs will contain any errors; core_ls will be the full
X##  list of old and bogus files.
X##
X
X##  Setup.
Xcd /usr/adm
XPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin
XHOST=`hostname`
Xrm -f core_ls core_errs core_unknown
X
X##  If first argument is "-i" then we're interactive.
Xif [ "x$1" = "x-i" ] ; then
X    shift
Xelse
X    exec 2>core_errs
Xfi
X
X##  Optional next argument is how old files should be before we complain.
XAGE=${1-5}
X
X##  Cute trick to get list of directly-mounted filesystems, only.
XFILESYSTEMS=`df | awk '$1 ~ /^\/dev\// {print $6}'`
X
X##  You might want to tweak the predicates in here.
Xfind ${FILESYSTEMS} \( \
X	    -name core -o -name a.out \
X	    -o -name 'drft.[0-9]*' \
X	    -name 'msg[0-3][0-9][JFMASOND]*' \
X	    -o -name ',*' \
X	    -o -name '#*' -o -name '.#*' \
X	    -o -name '*~' -o -name '.*~' \
X	    -o -name '.tpen*' \
X	\) -a -xdev -a -mtime +${AGE} -print \
X    | fmt -200 | sed -e 's@^@/bin/ls -l @' | sh >core_ls
X#  If you have xargs, it is more efficient.
X#   | xargs /bin/ls -l >core_ls
X
X##  Unlikely, but maybe we didn't find anything.
Xif [ ! -s core_ls ]; then
X    exec rm -f core_ls
Xfi
X
X##  Assuming a standard "ls", third field is the users.  Loop over list
X##  of all badguys.  The funky grep commands ignore filenames; be careful
X##  if your "ls -l" uses tabs.
Xfor c in `awk '{print $3}' <core_ls | sort -u` ; do
X    case $c in
X    _*|[0-9]*)
X	grep " $c " core_ls >>core_unknown
X	;;
X    *)  
X	(
X	    echo "You have the following old files on the ${HOST}:"
X	    grep " $c " core_ls
X	    echo "which are greater than ${AGE} days old."
X	    echo ''
X	    echo 'If you are finished with them, it would be nice to remove'
X	    echo 'them, freeing up the disk space.'
X	    echo ''
X	    echo 'Thanks,'
X	    echo ''
X	    echo "The Filesystem on ${HOST}"
X	    echo ''
X	) | \
X	    Mail -s "Old files on ${HOST}" $c
X# We use sendmail; MMDF is probably this:
X#	    v6mail -to $c -subj "Old files on ${HOST}"
X	;;
X    esac
Xdone
Xif [ -s core_unknown ] ; then
X    (
X	echo "Found unknown old files on ${HOST}:"
X	cat core_unknown
X    ) | \
X	Mail -s "${HOST}: No owner for these ancient files." root
X# We use sendmail; MMDF is probably this:
X#	v6mail -to root -subj "${HOST}: No owner for these ancient files."
Xfi
END



More information about the Comp.sources.misc mailing list