Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

9.30. Rotating Log Files

Problem

You want to control and organize your ever-growing log files.

Solution

Use logrotate, a program to compress and/or delete log files automatically when they are sufficiently old, perhaps after they have been stashed away on tape backups.

Add entries to /etc/logrotate.d/syslog, e.g.:

               /etc/logrotate.d/syslog:
/var/log/local0 /var/log/local1 ...others... {
        sharedscripts
        postrotate
                /bin/kill -HUP `cat /var/run/syslogd.pid`
        endscript
}

Discussion

Log files should be rotated so they won’t grow indefinitely. Our recipe shows a simple configuration that can be used with logrotate to do this automatically. After the files are shuffled around, the postrotate script sends a signal to the system logger to reopen the log files, and the sharedscripts directive ensures that this is done only once, for all of the log files.

You can add a separate configuration file (with any name) in the /etc/logrotate.d directory, as an alternative to editing the /etc/logrotate.d/syslog file. Separate entries can be used to tune the default behavior of logrotate, which is described by /etc/logrotate.conf, e.g., to rotate some log files more frequently.

See Also

logrotate(8), syslogd(8).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page