HOWTO Rotate logs on Sun Solaris

This article was first written in September 2004 for the BeezNest technical
website (http://glasnost.beeznest.org/articles/171).
There is no generalized system to rotate and compress logs in Solaris, like GNU logrotate on Linux or newsyslog on FreeBSD. Hopefully, Shaun Rowland wrote one: rotatelog. It is written as a Perl script meant to be run from cron, with a configuration file and documentation available. Note: Starting from Solaris 9, there is a standard tool, called logadm, to rotate logs. Go download the tar.gz file and untar it. Then go in the new directory, and execute make install. It will install everything by default under /usr/local/ (mainly /usr/local/sbin/rotatelog and /usr/local/etc/rotatelog.conf). Adapt the rotatelog.conf file to your needs/wishes. Here is a sample, working configuration file for Solaris 8:
# $Id: rotatelog.conf,v 1.2 2001/04/22 23:01:36 rowland Exp $

#####
#
# This a sample rotatelog configuration file.
#
#####

FILES:

# File (full path)    Trigger   Owner:Group     Mode  Compress  Archive Limit
# ================    =======   ===========     ====  ========  =============

/var/adm/wtmpx          4M      root:wheel      644     none            4
/var/adm/messages       8M      root:wheel      664     gz              5
/var/log/syslog         8M      root:wheel      664     gz              5

ACTIONS:

# Shell Command :file1,file2,file3 ... fileN
# ==========================================

rotate1                                 : /var/adm/wtmpx
kill -HUP `cat /var/run/syslog.pid`     : /var/adm/messages, /var/log/syslog

NOTIFY:

# Person to receive email rotation notification
# =============================================

root@localhost
Modify the section of the rotatelog script where appears the following lines to your actual setup:
# Solaris path settings.
my $compress = "/bin/compress";
my $gzip = "/usr/local/bin/gzip";
my $sendmail = "/usr/lib/sendmail";
my $hostname = "/bin/hostname";
On Solaris 8, it should be like this:
# Solaris path settings.
my $compress = "/usr/bin/compress";
my $gzip = "/usr/bin/gzip";
my $sendmail = "/usr/lib/sendmail";
my $hostname = "/usr/bin/hostname";
Please note that on Solaris 8 newsyslog exist, is already started from cron, and is a basic shell script meant only to rotate /var/adm/messages without even compressing it. Let's deactivate it, and put our rotatelog instead. Existing crontab:
# crontab -e

#ident  "@(#)root       1.19    98/07/06 SMI"   /* SVr4.0 1.1.3.1       */
#
# The root crontab should be used to perform accounting data collection.
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
10 3 * * 0,4 /etc/cron.d/logchecker
10 3 * * 0   /usr/lib/newsyslog
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
We'll comment line
10 3 * * 0   /usr/lib/newsyslog
by adding a '#' to it at the beginning and adding our line calling rotatelogs.Our crontab becomes:
#ident  "@(#)root       1.19    98/07/06 SMI"   /* SVr4.0 1.1.3.1       */
#
# The root crontab should be used to perform accounting data collection.
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
10 3 * * 0,4 /etc/cron.d/logchecker
#10 3 * * 0   /usr/lib/newsyslog
10 3 * * 0   /usr/local/sbin/rotatelogs
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean

Comments

I am working on a Solaris 5.10 v. server and got a request to:
“Rotate http-plugin.log once it reaches 1 MB”
I’ve been doing some research on Google about this but it’s been difficult to find a direct straight answer.
Is there a general, straight forward way to do this or is this a bit more complicated than that? Just wondering. Thanks.