Procmail Log File Rotation

Procmail Log File Rotation

Many C.S. computer account holders use procmail to filter their incoming e-mail. In most cases, procmail writes a log file which can get quite large over time. Therefore, we have set up a system to manage the size of these log files.


Many of us use the procmail program to filter our incoming e-mail. For example, procmail can be used to filter spam, to have certain messages go to particular mail folders, or to forward certain messages to other addresses. All one has to do is set up recipes (rules) in a ~/.procmailrc config file; the C.S. departmental e-mail system takes care of the rest.

Usually, a procmail log file is created (e.g., ~/mail/proc-log), and some details about every e-mail message processed (including spam) are appended to this file. This log file, though useful, can get very large over time, in some cases becoming hundreds of MBs. In order to moderate this, we have implemented an automatic procmail log file rotation system. At the start of each month, for each user, the system determines the name of the log file and rotates the file on a six month cycle. There is some provision for customizing this process.

Details & customization

Procmail is run by the C.S. e-mail system to process all incoming e-mail. Users can add customizations for special handling via the ~/.procmailrc config file. Usually there is an entry in .procmailrc to specify a log file; for example:


This indicates that the log file is ~/mail/proc-log. (See man procmailrc for more information.) Once a month, this file will be rotated.

What the log rotation program will do is look for a .procmailrc file in the home directory; parse this file to determine the exact path and filename for the log file; then perform some file moves to begin logging to a new file, but keep some old log file copies. Besides the current file, six previous copies will be kept.

The procmail log rotation program also accomodates some user-based customization:

Log file rotation

Log file rotation refers to some methodology for moving and renaming files such that some number of older versions are kept available. Though this might apply to any type of file, it is often applicable to log files, as they are continuously being appended to with new information, and so tend to grow indefinitely. So, for example with proc-log, if we want a six month rotation, then at the end of the first month, proc-log is moved to proc-log.1, and a new (empty) proc-log file is created; the next month, proc-log.1 is moved to proc-log.2, proc-log is moved to proc-log.1, and a new proc-log is created; after six iterations of this (proc-log, proc-log.1, ..., proc-log.6), then the oldest (proc-log.6) is deleted and the files are again rotated.

If you have any questions please contact the Lab staff.