shithub: logrotate

Download patch

ref: 7b390e5368973a5b162cc63a8db7bb6ee85cff14
author: Stephen Jones <smj@9p.sdf.org>
date: Wed Oct 20 13:56:28 EDT 2021

initial commit of logrotate

--- /dev/null
+++ b/README.md
@@ -1,0 +1,13 @@
+# logrotate
+
+A multi-generational log rotator.  Runs as the hostowner
+from cron.  Take the defaults or edit these 4 varables in
+the script:
+
+logdir		Where your log files live if not /sys/log
+logfiles 	What files you want rotated
+generations	How many generations to you want to keep
+maxsize		How big can the logfile get before its rotated
+
+Run from cron at midnight every sunday
+0 0 * * 0 $sysname pathto/logrotate
--- /dev/null
+++ b/logrotate
@@ -1,0 +1,43 @@
+#!/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 httpd/log 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
+	chmod -a $logdir/$i
+	>$logdir/$i
+	chmod +a $logdir/$i
+}
+
+for(i in $logfiles){
+	if(test -f $logdir/$i){
+		size=`{du -n $logdir/$i|awk '{print $1}'}
+		if(test $size -gt $maxsize){
+			Rotate $i
+		}
+	}
+}
+
+