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

jan96.tar


Listing 6: clf.sh--removes redundant records

#!/bin/sh
#
# clf - compress log file.
#
# SYNOPSIS
#    /usr/local/etc/clf filename [output_filename]
#
# DESCRIPTION
#    Removes redundant consecutive heartbeat records from the (presumed)
#    log file indicated by filename.  WARNING:  clf does not lock file-
#    name;  it should not be used on an active log file.
#
#    clf will write its output to filename.Y unless output_filename is
#    specified.
#

#
# Installation constants
#set -x

#
# Direct paths to programs used
AWK=/bin/awk
CAT=/bin/cat
CUT=/bin/cut
ECHO=/bin/echo
RM=/bin/rm
SED=/bin/sed
TR=/bin/tr
WC=/usr/ucb/wc

#
# Deal with command line options.
#
# filename -- it must be there.
if  [ X"$1" = X ]
then
$ECHO "Usage: $0 filename" 1>&2
exit 1
fi
#
# It could be zero length.
if  [ ! -s $1 ]
then
$ECHO "$0: file $1 has zero length." 1>&2
exit 2
fi
#
# output_filename -- either given or temporary
if  [ X"$2" = X ]
then
outfil=$1.Y
else
outfil=$2
fi

#
# Build and run awk(1) script that actually does the work.
#
LC=`$WC -l $1 | $SED 's/^ *//' | $TR ' ' : | $CUT -d: -f1`
$CAT << EOF > /tmp/clf.$$.awk
BEGIN {
LR = $LC
}
NR == 1 {
print
R[1] = \$1
R[2] = \$2
R[3] = \$3
R[4] = \$4
R[5] = \$5
R[6] = \$6
R[7] = \$7
}
NR > 1 && NR < LR {
if  (\$1 != "+")
{
if  (R[1] == "+")
{
print R[1] " " R[2] " " R[3] " " R[4] " " R[5] "
" R[6] " " R[7]
}
print
}
R[1] = \$1
R[2] = \$2
R[3] = \$3
R[4] = \$4
R[5] = \$5
R[6] = \$6
R[7] = \$7
}
NR == LR {
print
}
EOF
$AWK -f /tmp/clf.$$.awk $1 > $outfil
#
# Normal termination
$RM -f /tmp/clf.$$.*
exit 0