#!/bin/sh # Copyright (C) 2011 Glen Pitt-Pladdy # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # See: http://www.pitt-pladdy.com/blog/_20110501-200005_0100_syslog-ng_on_OpenWrt/ # logsize in blocks (typically 1024) above which we rotate LOGSIZE=64 # how many compressed generations to keep LOGGEN=5 # logfile LOG=/var/log/messages # check if we are ready to rotate if [ `ls -s $LOG | sed 's/^ *//' | cut -d ' ' -f 1` -lt $LOGSIZE ]; then # too small - skip this time exit 0 fi # we need to do the rotation i=$LOGGEN while [ $i -gt 0 ]; do # rotate one step newer=$(($i-1)) # check if we need to compress if [ -f $LOG.$newer.gz ]; then # already compressed - just rotate mv $LOG.$newer.gz $LOG.$i.gz elif [ -f $LOG.$newer ]; then # need to compress mv $LOG.$newer $LOG.$i gzip $LOG.$i fi # next do the previous generation i=$(($i-1)) done # rotate the current file mv $LOG $LOG.0 # kick syslog-ng to start a new file killall -HUP syslog-ng