#!/bin/csh

# this script runs from cron and does the following:
# 1.  Takes a log file as input
# 2.  Produces a summary record
# 3.  Appends the summary record to a summary file
# - wade 5/6/92

set WORKING_DIR = "/var/ti/util/"

# The argument supplied is the location of the log file
if ($#argv == 0 )  then
        /bin/echo "Usage: connections logfile"
        exit 1
endif

if (! -r $1 ) then
        /bin/echo "Cannot access:" $1
        exit 1
endif

set LOG_FILE = $1

# allow a new pips.log file to be started
mv $LOG_FILE $LOG_FILE.working

# convert the format of ($1) pips.log into one that can be read
# by the summary program.
if ( -r $LOG_FILE.convert ) then
	rm $LOG_FILE.convert
endif
grep active $LOG_FILE.working | \
  awk '{printf ":0:@:%s:%s %s %2d %s %s\n",$3,$4,$5, $6, $7,substr($8,1,4)}' > $LOG_FILE.convert

# create summary record
if (! -r $LOG_FILE.summary ) then
        echo > $LOG_FILE.summary
endif
${WORKING_DIR}summary D < $LOG_FILE.convert >> $LOG_FILE.summary

# add log file to historical file
if (! -r $LOG_FILE.archive ) then
	mv $LOG_FILE.working $LOG_FILE.archive
else
	cat $LOG_FILE.working >> $LOG_FILE.archive
	rm $LOG_FILE.working
endif

# cleanup
rm $LOG_FILE.convert
