13.06.2015 Views

Introduction to the Apache Web Server - ApacheCon

Introduction to the Apache Web Server - ApacheCon

Introduction to the Apache Web Server - ApacheCon

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16.9 Rotating log files<br />

16.9.1 Logfile::Rotate<br />

Logfile::Rotate is a Perl module. It is on <strong>the</strong> CD. Or you can get it from<br />

http://www.cpan.org/modules/by-module/Logfile/<br />

Unpack it somewhere, run <strong>the</strong> following:<br />

perl Makefile.PL<br />

make<br />

make test<br />

make install<br />

Or, <strong>to</strong> install <strong>the</strong> module from <strong>the</strong> CPAN shell:<br />

perl -MCPAN -e shell<br />

cpan> install Logfile::Rotate<br />

cpan> quit<br />

Then put <strong>the</strong> following code in<strong>to</strong> a file called rotatelogs.pl<br />

#!/usr/bin/perl<br />

use Logfile::Rotate;<br />

$logfile = new Logfile::Rotate(<br />

File => ’/usr/local/apache/logs/access_log’,<br />

Count => 5,<br />

Gzip => ’/bin/gzip’,<br />

Post => sub {<br />

‘/usr/local/apache/bin/apachectl restart‘;<br />

}<br />

);<br />

$logfile->rotate();<br />

Run <strong>the</strong> file a few times and see what happens <strong>to</strong> your log files. You’ll want <strong>to</strong> run this program every month<br />

(or week, or whatever) via cron or o<strong>the</strong>r scheduler.<br />

103

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!