1 AUTHOR: Hugo S. Cardozo <hugoa_c2004@yahoo.com>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: Logrotate: Keep your log files tidy
9 DESCRIPTION: This hint will help you to install and
11 logrotate for your (B)LFS system
13 ATTACHMENTS: * logrotate-3.6.8
14 <mirrordeslackware>/logrotate-3.6.8.tar.gz
16 PREREQUISITES: LFS installed and running.
25 Logrotate is an utility to take care of the log files of your system. It keeps
26 track of the size of the log files, and "rotates" them when needed. That means
27 the utility checks the size of the files, and if one of them is larger than a
28 certain size, the program performs some actions. That action can be: backup
29 and compress the file, remove it or mail it to an user, create a new empty
35 First, you need to compile and install popt-1.10.4. The BLFS book includes
36 the instructions for this. But, if for some (strange) reason you can`t get
37 the popt-1.10.4 tarball, you can use popt-1.6.3 either, or (maybe) any later
40 Now you can compile logrotate. Unpack the tarball and
42 tar xzf logrotate-3.6.8.tar.gz
46 Optionally, run the test suite:
54 The command "logrotate" needs a config file, which must be passed as an
55 argument to the command when executed. We will put that file in "/etc",
56 and name it "logrotate.conf".
58 Create the file with this command:
59 cat >> /etc/logrotate.conf << EOF
60 # Begin of /etc/logrotate.conf
62 # Rotate log files weekly
65 # Don't send mail to anybody
68 # If the log file is empty, it will not be rotated
71 # Number of backups that will be kept
72 # This will keep the 2 newest backups only
75 # Create new empty files after rotate old ones
76 # This will create empty log files, with owner
77 # set to root, group set to sys, and permissions 644
80 # Compress the backups with gzip
83 # RPM packages drop log rotation info in this directory
84 # so we include any file in it.
85 include /etc/logrotate.d
87 # End of /etc/logrotate.conf
90 Also, you can use the file "logrotate-default", which is in the logrotate
91 sources, in the "examples" directory. I use some of the lines of that file
94 When installing sysklogd, the LFS book defines some predefined log files in
95 "/etc/syslog.conf". We can rotate those files by adding their definitions to
96 logrotate.conf. So, to add them, run this command:
97 for logfile in $(find /var/log/* -type f); do
98 echo "$logfile {" >> /etc/logrotate.conf
99 echo "# If the log file is larger" \
100 "than 100kb, rotate it" >> /etc/logrotate.conf"
101 echo " size=100k" >> /etc/logrotate.conf
102 echo "}" >> /etc/logrotate.conf
103 echo "" >> /etc/logrotate.conf
106 For details on editing this file, see logrotate(8).
109 Logrotate as a Cron job
110 =======================
112 You can run logrotate just issuing "/usr/sbin/logrotate /etc/logrotate.conf"
113 but in this case, you should run that command by yourself, every day (or
114 week, or month...), if you want the program to work properly. This can be
117 Instead, you can run it as a cron job. For the further configuration,
118 I will assume that you have installed Fcron from the BLFS book.
120 Create a /etc/fcrontab file by issuing this command:
121 cat >> /etc/fcrontab << EOF
122 0 12 * * * 0 /usr/sbin/logrotate /etc/logrotate.conf
124 This will make fcron execute logrotate once a week, on Sunday, at noon.
125 For details on editing fcrontab, refer to fcrontab(1).
127 You will need the "check_system_crontabs" script from the fcron sources. If
128 you haven't installed it, do it by issuing:
129 tar xzf fcron-3.0.1.tar.gz
130 cp -v fcron-3.0.1/scripts/check_system_crontabs /usr/sbin
133 check_system_crontabs -v
135 check_system_crontabs -h
139 * Alexander E. Patrakov, for pointing me for the BLFS
141 popt (Before I used the popt included in Slackware 10.1)
146 CHANGELOG: 1.00 First release
147 1.1 Corrected popt section, fixed typos.