Penguin

logrotate(8) is a utility for maintenenace of system logs. It allows automatic rotation, compression, removal, and mailing of log files. Each log file can be handled daily, weekly, monthly, or when it grows too large.

logrotate is run by cron(8) and controlled by a config file (/etc/logrotate.conf) and files stored in /etc/logrotate.d.

If you want to get logrotate to do something useful for you, add a file in your /etc/logrotate.d directory (eg 'mailout'), containing

something like

/var/log/logfilename {

daily rotate 12 compress mail youremail@address.or.alias mailfirst

}

This should mail the logfile out to youremail@address.or.alias whenever logrotate runs - which is your systems 'midnight maintenance' is scheduled to be run (3 or 4 am usually, as most geeks dont like being interrupted at midnight for maintenance ;) To mail it to two ppl, add an alias in /etc/aliases with both email addresses included - this is probably the nicest method.

It'll keep 12 rotations, and start gzip compressing old logfiles. mailfirst tells it to mail out the most recently rotated logfile (The default is the one about to be killed.)

This is under DebianLinux. YourMileageMayVary under RedHat but it should be similar.

Oh, and this is all assuming that you are using syslog(3) to do your logging. If /var/log/logfilename is manually opened by whatever app you are using, I dont know how logrotate will handle it, if at all. you may need to use the postrotate keyword in your logrotate file to trigger a -HUP to your app, or even restart it (icky).


If you do not specify a value for the rotate parameter it defaults to 0 (ie. it doesn't rotate any logs, just deletes the old one straight away)


CategoryNotes