#!/bin/sh

COMDIR=/usr/local/bin
LOGDIR=/var/log/atsar
CURDAY=`date +%d`

if [ ! -d $LOGDIR ]
then
	echo $0: directory $LOGDIR not present >&2
	exit 1
fi

if [ -f /etc/atsar.conf ]
then
	$COMDIR/atsaftp     # count  ftp-requests added since previous call
	$COMDIR/atsahttp    # count http-requests added since previous call
fi

if [ $# = 0 ]
then
	$COMDIR/atsadc 1 1 $LOGDIR/atsa$CURDAY 2> /dev/null
else
	$COMDIR/atsadc $*  $LOGDIR/atsa$CURDAY 2> /dev/null
fi

# delete files older than one week at midnight
if [ `date +%H` -eq 0 ]
then
	find $LOGDIR -name 'atsa*' -mtime +7 -exec rm {} \;
fi

exit 0
