allbery@ncoast.UUCP (06/18/87)
This script prints nice summaries of people's disk usage, as they change
from day-to-day and week-to-week. The sample shown below is somewhat off,
because I just ran the thing twice to get two reports. I lifted this from
a source that would rather remain anonymous. I did some hacking to make
it more efficient (e.g., the "eval" stuff).
-rich $alz
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: diskuse.sh
# Wrapped by rsalz@pineapple.bbn.com on Thu Jun 18 07:30:28 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f diskuse.sh -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"diskuse.sh\"
else
echo shar: Extracting \"diskuse.sh\" \(2815 characters\)
sed "s/^X//" >diskuse.sh <<'END_OF_diskuse.sh'
X
X#! /bin/sh
X# Show report of disk usage. Should be run nightly from cron. The
X# report looks like this:
X# Thu Jun 18 01:12:26 EDT 1987
X# Filesystem kbytes used avail capacity Mounted on
X# /dev/ra0h 87519 70147 8620 89% /usr/politics
X#
X# Today Yester Change Week Change Directory
X# 21766 21766 0 +21766 bidden
X# 12645 12645 0 +12645 donaldson
X# 10632 10632 0 +10632 kemp
X# 4493 4493 0 +4493 emacs
X# 2810 2808 +2 +2810 pac
X# 1932 1932 0 +1932 common-cause
X# 1566 1566 0 +1566 guest
X# 1213 1213 0 +1213 root
X# 596 596 0 +596 reagan
X# 594 594 0 +594 bush
X# 349 349 0 +349 hart
X# 248 248 0 +248 kennedy
X# 51 51 0 +51 cuomo
X# 28634 4 0 +4 lost+found
X# Where the columns mean:
X# Today Today's usage
X# Yester What it was yesterday
X# Change Difference over the two days
X# Week What it was last week
X# Change Difference from last week
X# Directory Directory within this filesystem.
X
X# Our output goes to stderr; reports go to stdout
Xexec >&2
X
X# This is where the "raw" du reports go.
XUSEDIR=/usr/adm/.du
X# This is where the daily reports go.
XOUTDIR=/usr/adm/disk_use
X
X# Build filesystem list into commands to set shell variables.
XLIST=`awk -F: '{ printf "DEV=%s;FS=%s\n", $1, $2 }' </etc/fstab`
X
Xfor L in ${LIST} ; do
X # Get filesystem and disk device; skip unwanted ones.
X eval ${L}
X if [ "${FS}" = "/" -o "${FS}" = "/tmp" ] ; then
X continue;
X fi
X
X # Get names for du and pretty reports.
X I=`expr ${FS} : '.*/\(.*\)' '|' ${FS}`
X USE=${USEDIR}/${I}
X OUT=${OUTDIR}/${I}
X
X # Shift old du reports down...
X for I in 6 5 4 3 2 1 0 ; do
X touch ${USE}.${I}
X mv -f ${USE}.${I} ${USE}.`expr ${I} + 1`
X done
X
X # Get new du report.
X cd ${FS} ; du -s * | sort +1 >${USE}.0
X# cd ${FS} ; du * | grep -v '\.*/.*' | sort +1 >${USE}.0
X
X # Send output to report
X touch ${OUT}
X mv -f ${OUT} ${OUT}.BAK
X exec >${OUT}
X
X # Prolog
X date
X df ${DEV}
X echo
X awk </dev/null 'BEGIN {
X FMT="%6s %6s %6s %6s %6s %s\n"
X printf FMT, \
X "Today", "Yester", "Change", "Week", "Change", "Directory"
X }'
X
X # Compare today's usage with that of yesterday and a week ago.
X join -j1 2 -j2 2 -a1 ${USE}.0 ${USE}.1 | join -j1 1 -j2 2 -a1 - ${USE}.7 \
X | awk '\
X BEGIN {
X FMT="%6s %6s %6s %6s %6s %s\n"
X }
X {
X day = $2 - $3
X if (day > 0)
X dsign = "+"
X else
X dsign = ""
X week = $2 - $4
X if (week > 0)
X wsign = "+"
X else
X wsign = ""
X printf FMT, $2, $3, dsign day, $4, wsign week, $1
X }' | sort -nr
X
X # Send our output back to stderr.
X exec >&2
Xdone
X
END_OF_diskuse.sh
if test 2815 -ne `wc -c <diskuse.sh`; then
echo shar: \"diskuse.sh\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0