~drscream

Using logadm, a powerful log rotation tool

One of the secret and powerful tools that are mostly forgotten is logadm. The tool allows system and application logfiles to be rotated at a configureable interval.

The configuration file /etc/logadm.conf contains the information which logfile need to be rotated and how. logadm control the configuration file with some of the following options, check the manpage for more details:

General options:
        -w entryname    write entry to config file

Options which control how a logfile is rotated:
        -a cmd          execute cmd after taking actions
        -b cmd          execute cmd before taking actions
        -o owner        new empty log file owner
        -g group        new empty log file group
        -m mode         new empty log file mode
        -c              copying it and truncating the original

Options which control the expiration of old logfiles:
        -C count        expire old logs until count remain

logadm run on most solaris based systems each day at 3:10 am. With the -p option you could specify a period of time if required. I recommend to use as “entry name” the logfile including the path, this should be unique enough.

If you would like to rotate the exim main logfile every day without restarting the service I also recommend the option -c. This will copy the log entries from the old logfile and truncate it after.

                                      .- keep 10 files            .- copy and truncating
$ logadm -w /var/log/exim/main -p 1d -C 10 -o mail -g mail -m 640 -c -N
         `- write to config    `- one a day    `- owner and group    `- prevent error if file not exists

Because of the -w write entry to config file option, this line will appear in /etc/logadm.conf.

Maybe you’ve script that should send the exim panic log and rotate the logfile by his own? Yes this is also possible with logadm but you don’t require the -w option.

$ logadm -p now -C 10 -o mail -g mail -m 640 /var/log/exim/panic
          `- run the rotation of the logfile now

By rotating a logfile with logadm it adds .<number> at the end of the old files. This number increase by the date.

Please check the manpage for more options, logadm supports different log rotation types (count or size) and could also gzip your old files.


Send your comment by mail.