Summary of "Utility needed"

From: Ittai Hershman (ittai@shemesh.stern.nyu.edu)
Date: Wed Mar 06 1991 - 14:47:52 CST


I received about 15 messages, 10 people told me how I could write one --
which I already knew. 2 people asked for copies of what I received. 1
person wrote a script (apparently in response to my message) and sent it
to me untested.

Daniel Trinkle (trinkle@cs.purdue.edu) of Purdue University kindly
responded with his compressfs.sh script which he has given me permission
to repost. Dan's script also catches a condition I hadn't thought of
initially -- it doesn't try to compress files with names which end in
".Z".

This, by the way, was one of the reasons I didn't want to reinivent
the wheel: invariably these things take a few passes to get right and
I prefer to take advantage of other people's learning curve experiences.

Thank you all,
-Ittai

======================================================================
     Try my compressfs.sh script, it is exactly what you describe.

Daniel Trinkle trinkle@cs.purdue.edu
Dept. of Computer Sciences {backbone}!purdue!trinkle
Purdue University 317-494-7844
West Lafayette, IN 47907

======================================================================
#!/bin/sh
#
# Usage: compressfs fs
# compress old files in a file system and notify users
#
# Daniel Trinkle
# Computer Sciences Department
# Purdue University
# May 22, 1990
#
PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/etc
export PATH
USAGE="Usage: $0 fs"
TMP1=/tmp/compressfs.$$.1
TMP2=/tmp/compressfs.$$.2
MESG=/u1/trinkle/lib/compressfs.mesg
#
# Configuration tuning
#
# ADM - user to receive copy of user notices
# BIG - size of big files (in 512 byte blocks)
# OLD - old files (in days)
#
ADM=trinkle
BIG=20
OLD=30

if [ `whoami` != "root" ] ; then
    echo "ERROR: You must be root to run $0"
    exit 1
fi

if [ $# -ne 1 ] ; then
    echo $USAGE
    exit 1
fi

FS=$1

if cd $FS ; then
    :
else
    echo "ERROR: cannot change directory to $FS"
    exit 1
fi

INODE=`ls -lid | awk '{print $1}'`
if [ $INODE -ne 2 ] ; then
    echo "ERROR: $FS is not the root of a filesystem (inode != 2)"
    exit 1
fi

find . -type f -atime +$OLD -mtime +$OLD -size +$BIG ! -name '*.Z' -print | awk 'NF == 1 {print}' > $TMP1

USER_LIST=`awk '{split($1, p, "/"); print p[2]}' $TMP1 | sort -u`

for U in $USER_LIST ; do
    cp /dev/null $TMP2
    echo "Doing files for $U"
    grep "^\./$U/" $TMP1 | \
        while read FILE ; do
            if compress $FILE 2>/dev/null ; then
                echo $FILE >>$TMP2
            fi
        done
    (sed -e "s;FS;$FS;g" -e "s;BIG;$BIG;g" \
         -e "s;OLD;$OLD;g" -e "s;USER;$U;g" $MESG ; \
     sed -e "s;^\./$U/;;" $TMP2) | Mail -s "Old $FS/$U files compressed" $U $ADM
    rm -f $TMP2
done

rm -f $TMP1 $TMP2
======================================================================



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:11 CDT