#!/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/20/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 WORKING = "/var/ti/util/"
set LOG_FILE = ${WORKING}syslog.working
set SUMMARY_FILE = "/var/ti/logs/pips.syslog.summary"

# save old syslog and allow a new one to start
mv $1 ${LOG_FILE}
echo > $1
kill -1 `cat /etc/syslog.pid`
#/etc/syslog&

set YEAR = `date | awk '{print $6}' `
set MONTH = `date | awk '{print $2}' `
set DAY = `date | awk '{print $3}' `

# if this script is running on the first day of a new
# year, then use previous year
if ($MONTH == "Jan" && $MONTH == 1) then
	@ YEAR--
endif

# make sure that the summary file exists
if (! -r $SUMMARY_FILE ) then
        echo > $SUMMARY_FILE
endif

# convert the log file into one that can be read by the
# summary program.  See network2.h for the transaction type.
# first find all "good" records from the log file
grep closed $LOG_FILE | awk '{printf ":0:}:%s:??? %s %2d %s %s\n", $12,$1,$2,$3,'$YEAR'}' | \
	${WORKING}summary D >> ${SUMMARY_FILE}

# cleanup
if (! -r $1.archive ) then
	mv ${LOG_FILE} $1.archive
else
        cat $LOG_FILE >> $1.archive
	rm ${LOG_FILE}
endif

