shithub: rc

ref: 15cde29629e8ecd1952e791996a2fc517337bbdd
dir: /logrotate/

View raw version
#!/bin/rc

#
# edit these 4 variables to your preference
# 0	0 * * 0 $sysname /usr/glenda/bin/logrotate
#
logdir=/sys/log
logfiles=(auth cpu cron dns gemini listen mail runq smtp smtp.fail smtpd)
generations=14
maxsize=1024000

if(! test -d $logdir){
	echo $logdir does not exist
	exit
}

fn Rotate{
	gen=$generations
	while(test $gen -ge '0'){
		pgen=`{echo $gen - 1|bc}
		if(test -f $logdir/$1.$pgen.gz){
			cp $logdir/$1.$pgen.gz $logdir/$1.$gen.gz
			chmod 0700 $logdir/$1.$gen.gz
		}
		gen=$pgen

	}
	gzip -c $logdir/$1 > $logdir/$1.0.gz
}

for(i in $logfiles){
	if(test -f $logdir/$i){
		size=`{du -n $logdir/$i|awk '{print $1}'}
		if(test $size -gt $maxsize){
			Rotate $i
			#
			# I is dum - logfile are open/append at boot so I caveman smash. help me.
			#
			rm -f $logdir/$i
			touch $logdir/$i
			chmod 0662 $logdir/$i
			chmod +t $logdir/$i
		}
	}
}