Linux logrotate: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:
exit 0
exit 0
</syntaxhighlight>
</syntaxhighlight>
The configuration file is [[#Configuration|/etc/logrotate.conf]].


=Installation=
=Installation=

Revision as of 20:19, 12 February 2018

External

Internal

Overview

logrotate is a tool that is run periodically - by default, daily - by cron. Every tine it is executed, logrotate reads its configuration files and manages log files declared in those configuration files, according to the specified rules.

A log rotation consists in renaming the current log fie, so my.log becomes my.log.1, my.log.1 becomes my.log.2 and so forth, and setting up a new my.log log file. The number of log files to be retained is specified in the configuration. Additional operations like compression may be specified.

The command is /usr/sbin/logrotate, and the cron configuration file that triggers logrotate to be executed once a day is /etc/cron.daily/logrotate:

#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

The configuration file is /etc/logrotate.conf.

Installation

yum install -y logrotate

Footprint

./usr/sbin/logrotate
./etc/logrotate.d
./etc/cron.daily/logrotate
./etc/logrotate.conf
./etc/rwtab.d/logrotate
./var/lib/logrotate

Configuration

The configuration file is /etc/logrotate.conf.