Often times it is useful to log messages from scripts. This can done using
the
This would send the specified message to the same place other
One common problem is what to do with all of the log messages. If you do a
lot of logging (particularly if everything is sent to a central server), you
can fill up your
It is a fairly simple matter to write a
As its name implies, the goal of the
Two files define how
The configuration file tells
The
A very simple
At the top are two global options, followed by a logfile definition for
The first line says that all error messages are sent (mailed) to root at the logserver. The second line says that log files are to be compressed after they are rotated.
The logfile definition consists of the logfile name and the directives to
apply, which are enclosed within curly brackets. The first line in the
logfile definition says to rotate the 4 times before being removed. The next
line says to rotate the files once a week. Together these two lines mean
that any given copy of the
The next three lines are actually a set. The postrotate directive says that
what follows should be done immediately after the log file has been rotated.
In this case,
It is also possible to specify an entire directory. For example, you could
rotate all of the
As I mentioned, you can also rotate logs based on their size. This is done by
using the
Although you can ease the management of your log files with just the options
we discussed, there are an incredible number of additional options which you can
use. Table 3 contains a list of options you can use with a brief explanation.
For more details see the logrotate(1)
Table 3 – logrotate options
compress/nocompress – compresses or does not compress old versions of logs.
delaycompress – Wait until the next cycle to compress the previous log.
create mode owner group – Log file is recreated with this mode, owner and group. (nocreate overrides this.)
daily, weekly, monthly – Rotate logs in the indicated interval.
errors
ifempty – Rotate the logs even if they are empty. (notifempty overrides this.)
include file_or_directory – Include the indicate file at this point. If a directory is given, all real files in that directory are read.
mail
olddir directory – old logs are moved to this directory, which must be on the same physical device. (noolddir overrides this.)
postrotate/endscript – delimits commands run after the log is rotated. Both must appear on a line by themselves.
prerotate/endscript – delimits commands run before the log is rotated. Both must appear on a line by themselves.
rotate count – Rotates the log ‘count’ times before being removed.
size size – Log files greater than ‘size’ are removed.
tabooext [+] list – list of files not to include. A plus-sign means the files are added to the list rather than replacing it.