SOLARIS 10: HOW TO INSTALL LOGROTATE PACKAGE

SOLARIS 10: HOW TO INSTALL LOGROTATE PACKAGE

(https://lucamerello.wordpress.com/2014/04/13/solaris-10-how-to-install-logrotate-package/)

Logrotate is a great utility designed to administer many large log files generated by the operating system or applications that run on it. It allows automatic rotation, compression, removal and mailing of logs, handling them daily, weekly, monthly or when they grow too large. By means a simple configuration file executed by the logrotate command in a cron job, you can manage all your logs easily and safely.

In this post we will see how to install the logrotate package, downloadable from Unix Packages exactly like all the libraries needed to run it.

First of all, the pre-requisites are as follows:

§  libgcc-3.4.6-sol10-platform-local.gz

§  libintl-3.4.0-sol10-platform-local.gz

§  libiconv-1.14-sol10-platform-local.gz

§  popt-1.16-sol10-platform-local.gz

§  gettext-0.18.3-sol10-platform-local.gz

§  ncurses-5.7-sol10-platform-local.gz

§  libxml2-2.9.1-sol10-platform-local.gz

§  expat-2.0.1-sol10-platform-local.gz

§  zlib-1.2.8-sol10-platform-local.gz

§  gzip-1.6-sol10-platform-local

where platform can be “sparc” or “x86”.

The installation process should be carried out with the “root” user:

# su - root

Change directory to the location where logrotate package has been stored (usually /tmp directory):

# cd /tmp

Then unzip and install:

# gzip -d logrotate-3.8.6-sol10-platform-local.gz

# pkgadd -d logrotate-3.8.6-sol10-platform-local

# rm logrotate-3.8.6-sol10-platform-local

Before starting to take advantage of logrotate’s features, you need to create the path for the configuration file with “root” user as owner:

# cd /etc

# mkdirlogrotate.d

# chownroot:syslogrotate.d

In this way, the most important files installed are the following:

§  /usr/local/sbin/logrotate (main command file)

§  /etc/logrotate.d/ (path of configuration files)

§  /var/log/logrotate.status (status file)

§  /usr/local/doc/logrotate (documentation)

Usage

I will not go into the explanation of the various features offered by logrotate because the official documentation of the command provides a valuable support to the end user, rather I will describe a simple use case.

Assuming that you have already prepared your own configuration file named “my-logrotate-config” and that it has been copied in /etc/logrotate.d, you have to complete an initialization phase so that logrotate can execute your instructions automatically.

First of all, debug your script without executing it, in order to check the validity of syntax:

# /usr/local/sbin/logrotate -d /etc/logrotate.d/my-logrotate-config

Then, force a first execution of the configuration file so as to initialize the state of your commands in the logrotate’s status file:

# /usr/local/sbin/logrotate -f /etc/logrotate.d/my-logrotate-config

Finally, this task can be scheduled (for example at midnight of every day) editing your user’s crontab:

# export EDITOR=vi

# crontab -e

...

# LOGROTATE

00 00 * * * /usr/local/sbin/logrotate /etc/logrotate.d/my-logrotate-config > /dev/null 2>&1

...

That’s all, enjoy your new log manager!