Cover V05, I01
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

jan96.tar


Listing 2: cdl.sh--collapses daily logs

#!/bin/sh
#
# cdl - collapse daily log(s).
#
# SYNOPSIS
#    /usr/local/etc/cdl [-r] [logdir]
#
# DESCRIPTION
#    Uses clf(8L) to compress daily log files in directory logdir.
#    If logdir is unspecified,  it defaults to LOGDIR.
#
#    If the "-r" flag is present,  the uncompressed files are re-
#    moved after the corresponding compressed version has been suc-
#    cessfully written.
#
#    All uncompressed inactive log files are processed.
#
# CALLS
#    /usr/local/etc/clf
#
# Installation constants
#set -x
SHLDIR=/usr/local/etc
EXEDIR=$SHLDIR
LOGDIR=/var/log
REMOVE=F
SFX=

#
# Direct paths to programs used

CUT=/bin/cut
DATE=/bin/date
FIND=/bin/find
LS=/bin/ls
RM=/bin/rm
SED=/bin/sed
TR=/bin/tr

#
# Begin.
#
# Deal with command line argument(s).
if  [ X"$1" = X"-r" ]
then
REMOVE=T
shift
fi
if  [ X"$1" != X ]
then
LOGDIR=$1
if  [ X"$LOGDIR" = X"." ]
then
EXEDIR=.
SFX=".sh"
fi
fi

#
# Construct list of files to compress.
$DATE '+%y %m %d %H %M %S' > /tmp/cdl.$$.date
YY=`$CUT -d' ' -f1 /tmp/cdl.$$.date`
MM=`$CUT -d' ' -f2 /tmp/cdl.$$.date`
DD=`$CUT -d' ' -f3 /tmp/cdl.$$.date`
HH=`$CUT -d' ' -f4 /tmp/cdl.$$.date`
MN=`$CUT -d' ' -f5 /tmp/cdl.$$.date`
SS=`$CUT -d' ' -f6 /tmp/cdl.$$.date`
$RM -f /tmp/cdl.$$.date
YY=`expr $YY + 1900`
FN=$LOGDIR/D.$YY.$MM.$DD
LF=`$LS -t $LOGDIR/D.[0-9]*.[0-1][0-9].[0-3][0-9] | tr '\12' ' '`
if  [ X"$LF" = X ]
then
exit 0
fi

#
# Compress 'em all except today's.
for F in $LF
do
if  [ ! -f $F.Y -a X"$F" != X"$FN" ]
then
$EXEDIR/clf${SFX} $F
fi
done

#
# Remove uncompressed files (except the two most recent).
if  [ X"$REMOVE" = X"T" ]
then
N=0
for F in $LF
do
if  [ $N -gt 0 ]
then
if  [ -s $F.Y -a  X"$F" != X"$FN" ]
then
$RM -f $F
fi
fi
N=`expr $N + 1`
done
fi

#
# Normal termination
exit 0