How To logrotate httpd log Files

I need to logrotate logs in directories in /var/log/httpd/. There are 4 directories in /var/log/httpd/... these directories  are /var/log/httpd/access/
/var/log/httpd/debug/
/var/log/httpd/error/ 
/var/log/httpd/required/

Each of the access, required, error and debug directories have around 20 to 30 access log files of different locations for example:mumbai-access.log, pune-access.log etc..same is the case for 'error' dir 'required' dir and 'debug' dir in /var/log/httpd/

I need to clean up the logfiles in all the 4 directories access, error, debug and required...

I have made a custom logrotate file as follows:
/etc/logrotate.d/httpd-logs

Answer:

The following will rotate on weekly and it will keep last 4 log files and all other old compressed logs will be removed automatically.

Code:

"/var/log/httpd/access/*.monitor.com-access_log" "/var/log/httpd/error/*.monitor.com-error_log" "/var/log/httpd/request/*.monitor.com-ssl_request_log" "/var/log/httpd/debug/*.monitor.com-rw_log"
{
    weekly
        missingok
        copytruncate
        rotate 4
        compress
        notifempty
        sharedscripts
        postrotate
           /sbin/service httpd reload > /dev/null 2>/dev/null || true
        endscript
}
 

Above /sbin/service is compatible with centos / rhel / fedora linux. 

For other distro use direct /etc/init.d/ path. 

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.