logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

Normally, logrotate is run as a daily cron job. It will not modify a log multiple times in one day unless the criterium for that log is based on the logs size and logrotate is being run multiple times each day, or unless the -f or -force option is used.

Any number of config files may be given on the command line. Later config files may override the options given in earlier files, so the order in which the logrotate config files are listed in is important. Normally, a single config file which includes any other config files which are needed should be used. If a directory is given on the command line, every file in that directory is used as a config file.

If no command line arguments are given, logrotate will print version and copyright information, along with a short usage summary. If any errors occur while rotating logs,logrotate will exit with non-zero status.

[[email protected] httpd]# logrotate
logrotate 3.7.1 - Copyright (C) 1995-2001 Red Hat, Inc.
This may be freely redistributed under the terms of the
GNU Public License

Usage: logrotate [-dfv?] [-d|--debug] [-f|--force] [-m|--mail command]
        [-s|--state statefile] [-v|--verbose] [-?|--help] [--usage]
        [OPTION...] 
[[email protected] httpd]#

In linux, CentOS, logrotate configuration files are in folder /etc/logrotate.d

[[email protected] logrotate.d]# ls -l
total 96
-rw-r--r--  1 root root 144 Feb 17  2005 acpid
-rw-r--r--  1 root root  86 May 29 09:40 apf
-rw-r--r--  1 root root 161 Jan 11 13:19 cups
-rw-r--r--  1 root root 174 Jan  5 11:57 httpd
-rw-r--r--  1 root root 571 Feb 17  2005 mgetty
-rw-r--r--  1 root root 345 Oct  7  2005 mysqld
-rw-r--r--  1 root root 136 Feb 17  2005 ppp
-rw-r--r--  1 root root 319 Mar  9 03:04 psacct
-rw-r--r--  1 root root  61 Mar  9 03:02 rpm
-rw-r--r--  1 root root 228 Feb 17  2005 syslog
-rw-r--r--  1 root root  32 Feb 22  2001 up2date
-rw-r--r--  1 root root  89 Feb 18 08:38 yum
[[email protected] logrotate.d]#

Lets see the content of file "httpd" this is configuration file used by logrotate to rotate Apache log files.

[[email protected] logrotate.d]# cat httpd
/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2>
 /dev/null || true
    endscript
}
[[email protected] logrotate.d]#

For how to use logrotate to rotate your log file, read "man logrotate"

Get in touch with us

Questions? Concerns? Comments? We want to hear from you!
Drop us a line with whatever is on your mind and we will get back to you ASAP!!