#! /bin/sh
#
# squid		Daily cron script for squid.
#
# Version:	@(#)squid.cron.daily  1.10  13-Nov-1996  miquels@cistron.nl
#

LOGDIR=/var/log/squid

cd $LOGDIR || exit 1

rotate () {
  for i in 6 5 4 3 2 1 0
  do
	if [ -f $1.$i ]
	then
		gzip -f -9 $1.$i
	fi
	if [ -f $1.$i.gz ]
	then
		mv -f $1.$i.gz $1.$[$i + 1].gz
	fi
  done
}
 
#
# Compress the old logfiles. No, we can't use savelog since squid
# may do logfile rotation itself! We'll have to work around this.
#
rotate access.log
rotate cache.log
rotate hierarchy.log
rotate store.log

#
# See if squid rotates the logfile for us.
#
R=`grep '^logfile_rotate' /etc/squid.conf | sed 's/^.* //'`
if [ "$R" = 0 ]
then
	# Do rotate ourself.
	mv access.log access.log.0
	mv cache.log cache.log.0
	mv hierarchy.log hierarchy.log.0
	mv store.log store.log.0
fi

# Now, let squid rotate or at least just flush the logfiles.
kill -USR1 `cat /var/run/squid.pid`

# Rotate the squid.out logfile
sleep 5
savelog -c 3 squid.out > /dev/null 2>&1

