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:
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
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)
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: