1. Home
  2. Computing & Technology
  3. Perl

Log Rotation - How to rotate your server log files with Perl
Rotating the error log

by Kirk Brown
for About.com

Next up, we need to take care of the error logs. We do this in the exact same way as we rotated the access logs, starting with setting up the file names.

$error_file = "mywebsite.com-error_log";
$error_archivefile = strftime("$error_file.%Y-%m-%d", localtime);
$error_archivezip = "$error_archivefile.tar.gz";
Then using the system function, we move the original file to the new archive name, and tar and zip the file to create the actual archive zip file.
system "mv $error_file $error_archivefile";
system "tar -czf $error_archivezip $error_archivefile";
Next, let's delete the un-zipped archive file and mv the zipped one on into the archives directory.
system "rm $error_archivefile";
system "mv $error_archivezip archives/";
Last but not least, we'll restart the web server using the apachectl script - you should note that depending on your configuration and server, this part will probably be different on your machine. The important thing to do it restart the server, however it's done, so that the log files can be re-created as blanks.
`/usr/local/apache2/bin/apachectl restart`;
Previous: Rotating the access log
Explore Perl
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Perl
  4. Perl Tutorials
  5. Log Rotation - How to rotate your server log files with Perl>

©2009 About.com, a part of The New York Times Company.

All rights reserved.