#!/bin/sh
#
# Submit path statistics based on ninpaths
# $Id: sendinpaths,v 1.1.2.2 2002/09/26 23:53:35 rra Exp $

# Assuming the ninpaths dump files are in ${MOST_LOGS}/path/inpaths.%d

. /var/lib/news/innshellvars
cd ${MOST_LOGS}/path
ME=`innconfval pathhost`
report=30
keep=14
TMP=tmp$$
defaddr=pathsurvey@top1000.org

# Renice to give other processes priority, since this isn't too important.
renice 20 -p $$ > /dev/null

trap "rm -f $TMP; trap 0; exit" 0 1 2 15
# Make report from (up to) $report days of dumps
find . -name 'inpaths.*' ! -size 0 -mtime -$report -print |\
 sed 's/^/-u /' > $TMP

if [ ! -s "$TMP" ] ; then
  echo "No data has been collected this month!"
  exit 1
fi

if [ "$1" = "-n" ] ; then
  ninpaths `cat $TMP` -r $ME
else
  ninpaths `cat $TMP` -r $ME |\
   $MAILCMD -s "inpaths $ME" ${1:-$defaddr}
  # remove dumps older than $keep days
  find . -name 'inpaths.*' -mtime +$keep -exec rm '{}' \;
fi

exit 0
