User Tools

Site Tools


Logrotate for pruning log files

[ Classic Linux and DirectAdmin. ]

The logrotate program can be used for automatically pruning log files such as those, for example, created by the procmail program.

The insructions below assume that you have configured your  .procmailrc  file to log to a file  procmail.log  in a subdirectory procmail inside your home directory. So the full pathname of the log file will be  ~/procmail/procmail.log  where ~ refers to your home directory.

To automatically prune this file, you will need to do two things.

First, create a file called  logrotate.conf  inside that same procmail subdirectory. The contents of this file will be as shown below.

Second, create a cron job that runs the logrotate command once a day. This will cause the procmail log file to be rotated across multiple generations, and to be kept limited in size as specified.

The cron job will look something like this:

15 1 * * * /usr/sbin/logrotate -s $HOME/procmail/.logrotate.state $HOME/procmail/logrotate.conf

The contents of logrotate.conf inside the procmail subdirectory will look like this:

# $Id: logrotate.conf 13371 2021-01-17 00:04:29Z svn $
# $URL: svn+ssh:// $

# The # character begins a comment.

# A personal logrotate file.

# In crontab, runs logrotate once a night at 1:15 am.
# Normal:
#   15 1 * * * /usr/sbin/logrotate -s $HOME/procmail/.logrotate.state $HOME/procmail/logrotate.conf
# Verbose, will cause output to be sent to you in email.
#   15 1 * * * /usr/sbin/logrotate -v -s $HOME/procmail/.logrotate.state $HOME/procmail/logrotate.conf

~/procmail/*.log {
   ## maxsize 100k
   maxsize 1M
   ## maxsize 10M
   ## maxsize 100M
   ## maxsize 1G
   rotate 5
hints/logrotate.txt · Last modified: 2021/02/07 06:08 by admin