Listing 1: maxsize.sh -- Command file run by cron
:
######################################################
# maxsizesh - this is the original file pruning
# program. It reads the maxsize.rc parameter
# file and prunes the specified files
######################################################
# this file should NOT be world writeable. it is run
# from root cron
basedir=/usr/work/local/parms
log=$basedir/maxsize.log ; export log
sizeprog=$basedir/flimit ; export sizeprog
parmfile=$basedir/maxsize.rc
sysadm="stevei glenbo sneed"
mailer=/bin/mail
date >> $log
# loop through the lines in the parameter file
while read lfile tot_lines perms owner other
do
# skip comments, spaces, blank lines, colons
case "$lfile" in
\#|\ |""|\#*|\:) continue ;;
esac
export lfile tot_lines perms owner
test -f "$lfile" || {
echo "Error: $lfile $tot_lines $perms \
$owner" >> $log
echo "missing file: $lfile" |
$mailer -s maxsize.sh $owner
continue
}
# don't allow setid bits. look for s
if echo "$perms" | grep s
then
echo " Error: bad permissions(1): $perms"
echo "bad perms in maxsize.sh $lfile \
$tot_lines $perms $owner" | $mailer $sysadm
continue
fi
# don't allow setid bits. look for 4xxx
x=`echo $perms | sed -e 's/4[0-9][0-9][0-9]//g'`
if test "$x" = ""
then
echo " Error: bad permissions(2): $perms"
echo "bad perms in maxsize.sh $lfile \
$tot_lines $perms $owner" | $mailer $sysadm
continue
fi
/bin/su "$owner" -c "
if test -f $lfile
then
$sizeprog $lfile $tot_lines
chmod $perms $lfile
chown $owner $lfile
exit 0
else
echo \" Failed: $?: $lfile $tot_lines \
$perms $owner\" >> $log
exit 1
fi "
echo "$lfile $tot_lines $perms $owner" >> $log
done < $parmfile
echo "maxsize.sh ran" | $mailer -s reminder $sysadm
exit 0
|