#!/bin/sh
# waisdata script
# I adapted this script from someplace, but I can't remember where
# It takes the current month on the command line
#
# Modify the next four lines to match your configuration
# - logdir is the location of your WAIS server log
# - server is the name of the server log file
# - year is (obviously) the current year.  It only needs to be changed
#   once a year, for convenience
# - dbname is the name of a WAIS database
#   Extending this to more than one database per server is left as
#   and exercise to the reader

logdir=/data/Logs
server=$logdir/WAISserver.log
year=1994
dbname=GCMD

workdir=/data/Logs/waisdata
temp=$workdir/waisdata1
temp2=$workdir/waisdata2


# Number of connections
NUM=`egrep -i $1" " $server | egrep $year | egrep Init | wc -l`
echo "Total of" $NUM "connections to the WAIS server for" $1 $year

# Searches
echo
echo "Searches:"
NUM=`egrep -i $1" " $server | egrep $year | egrep Search | grep $dbname | wc -l`
echo "Total of" $NUM "searches of the database"


# Retrievals
echo
echo "Retrievals:"

NUM=`egrep -i $1" " $server | egrep $year | egrep Retrieving | grep $dbname | wc -l`
echo "Total of" $NUM "document retrievals"


echo
echo "Most connections from:"
egrep -i $1" " $server | egrep $year | fgrep Init | sed -e 's/.*from //' | \
	sort | uniq -c | awk '$1 >= 1 { print $0 } ' | sort -nr | \
	awk ' { print $1 ": " $3 } ' 

echo
echo "Individual Stats - Searches:"
egrep -i $1" " $server | egrep $year | egrep Search | \
	sed -e 's/.*Database: //' | grep -v returning | \
	awk ' { print $1 } ' | sed -e 's/,//' | sort | uniq -c | sort -nr

echo
echo "Individual Stats - Retrievals:"
egrep -i $1" " $server | egrep $year | egrep Retrieving | \
	sed -e 's/.*database //' | sort | uniq -c | sort -nr



