#!/bin/csh

# this script runs from cron and does the following:
# this script takes the transaction file as an argument,
# which is usually pips.trans.log
# 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

# 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
set WORKING_DIR = "/var/ti/util/"

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

# create summary record
if (! -r $LOG_FILE.summary ) then
        echo > $LOG_FILE.summary
endif
${WORKING_DIR}summary D < $LOG_FILE.working >> $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
endif

# find the times the server restarted
if (! -r $LOG_FILE.starting ) then
        echo > $LOG_FILE.starting
endif
grep -i 'Starting server' $LOG_FILE.working | \
awk '{printf "%s %s %2d %s %s\n", substr($2,8,3), $3, $4, $6, $5}' >> $LOG_FILE.starting

# find the active providers
if (! -r $LOG_FILE.providers ) then
        echo > $LOG_FILE.providers
endif
grep :p: $LOG_FILE.working | \
awk -F: '{printf "%s %s %s\n", substr($6,1,10), substr($8,4,4), $4}' >> $LOG_FILE.providers

# cleanup
rm $LOG_FILE.working
