#! /bin/sh
#
#	@(#)newsyslog.sh 1.3 89/06/22 SMI
#
yes () {
set +x
while :
do
 echo "$@"
done
}
rotatelog () {
    cd `dirname $1`
    log=`basename $1`
    if [ ! -s "$log" ]; then return ; fi
    prev=
    for i in `echo \`yes "" | cat -n | head -$3 | sort -nr\` ` 0
    do
	if [ "$prev" = "" ]; then prev=$i; continue; fi
	test -f $log.$i.Z && mv $log.$i.Z $log.$prev.Z
	prev=$i
    done
    mv $log $log.0
    compress="$1.0 $compress"
    cp /dev/null $log
    chgrp 0 $log
    chmod $2 $log
}
PATH=/usr/bin:$PATH
export PATH

rotatelog /var/adm/messages 640 3
rotatelog /var/adm/authlog 640 7
rotatelog /var/adm/daemonlog 640 7
rotatelog /var/adm/authlog.info 640 3
rotatelog /var/adm/syslog 640 3
rotatelog /var/adm/ntplog 640 5
rotatelog /var/adm/tacacs.log 640 5
if [ -n "$compress" ]
then
    kill -HUP `cat /etc/syslog.pid`
    sleep 3
    compress -f $compress
fi

#
# Do the accounting.
#
cd /var/adm
/usr/lib/acct/turnacct switch
# Move the new pacct file aside and restore the old pacct file.
# This way rotate logs will work.
mv pacct pacct.new
mv pacct1 pacct
rotatelog /var/adm/pacct 640 3
mv pacct.new pacct
compress -f pacct.0
exit 0
