#!/bin/csh -f
#
# spacegripe - identify and send mail to disk hogs
#
# usage: spacegripe partition-name
# partition-name should be a path name (/users, etc.), not a device name
#
set partition = `echo $argv[1] | sed 's/\///g'`
#
# Extract users from passwd file.
#
cat /etc/passwd | \
awk -F: '{ print $6 }'  |\
grep ${argv[1]}/ > /tmp/$partition.homedirs
#
# Determine who the hogs are - people with 750 or more disk blocks
#
du -s `cat /tmp/$partition.homedirs` | sort -nr |\
awk '{if ($1 > 749) print $0}' > /tmp/$partition.du.users
#
# Extract usernames.
#
sed 's/^.*.\///' < /tmp/$partition.du.users > /tmp/$partition.users
#
# compose a letter...
#
cat << MUCK > /tmp/$partition.message
The Disk partition on which your home directory resides is almost full.

The following is a list of home directories and 
their sizes measured in Kilobytes:

MUCK
cat /tmp/$partition.du.users >> /tmp/$partition.message
cat << MUCK >> /tmp/$partition.message

As a large consumer of space on this partition, you should consider
deleting unwanted files.  This disk partition is backed up at regular
intervals. Anything that you delete may be retrieved from these
backup tapes in an emergency. 

For large files that you need regularly, you might consider the 'compress'
program. Do a 'man compress' for more info.

This situation is critical. It requires immediate action on your part.

If you have any technical problems, please send mail to the system
administrator. 

Sincerely,

spacegripe@`hostname`.
MUCK
#
/usr/ucb/mail -s "`hostname`:/$partition is very full" \
    `cat /tmp/$partition.users` systems < /tmp/$partition.message
#
cd /tmp
rm $partition.*
