Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 May 1996 10:48:35 -0400 (EDT)
From:      System Administrator <root@fledge.watson.org>
To:        questions@freebsd.org
Subject:   /etc/monthly, /etc/daily -- log rotation
Message-ID:  <Pine.BSF.3.91.960501104623.22525A-100000@fledge.watson.org>

next in thread | raw e-mail | index | archive | help

While perusing a BSDI system I used to administrate, I found the 
following code in /etc/monthly and /etc/daily that seemed to make a lot 
more sense that some of the stuff I saw in our equivilant files:

rotate() {
        file="$1"; shift
        rm -f "$file.$1" "$file.$1.gz"
        for i in "$@"; do
                [ "$i" = "0" ] && j="" || j=".`expr $i - 1`"
                [ -f "$file$j.gz" ] && mv -f "$file$j.gz" "$file.$i.gz"
                [ -f "$file$j" ] && mv -f "$file$j" "$file.$i"
                [ "$i" = "0" -a -x $file.scan ] && $file.scan "$file.$i"
                [ -f "$file.$i" ] && [ "X$ziplog" = "XYES" ] && /usr/bin/gzip "$file.$i"
        done
        cp /dev/null "$file"; chmod 644 "$file"
}

Calling is done as follows:

rotate /var/log/maillog 6 5 4 3 2 1 0
rotate /var/log/wtmp 6 5 4 3 2 1 0
rotate /var/log/popper 4 3 2 1 0

Etc.  It seems a lot more modular and configurable, etc.  It certainly 
makes the script files seem more readable -- maybe we should consider 
adopting a similar rotate call?

Robert Watson
robert@fledge.watson.org / http://www.watson.org




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.960501104623.22525A-100000>