#!/usr/local/bin/perl

# First do what we can while the web server still is running...
# Get the pid of the web server
$webserverpid = `cat /var/local/www/logs/httpd.pid`;
$log = "/var/local/www/logs/access_log";
$ylog = "/var/local/www/logs/yesterday_log";
# Read in the current log
open(LOG, $log);
$/ = '';
while(<LOG>){
    ($a, $a, $a, $a $hour, $minute, $sec, @trash) = split(/[ :]+/, $_);
    if($hour >= $lhour){
	$yesterday .= $_."\n";
	$lhour = $hour;
    }
    else{
	$today .= $_."\n";
    }
}

#Quick kill and replace !

kill $webserverpid;
rename($log, "/var/local/www/logs/access_log.old");
open(LOG, ">$log");
print LOG $today;
close(LOG);
system("/var/local/www/start");

unlink($ylog);
open(PME, ">$ylog");
print PME $yesterday;
close(PME);

exec("/var/local/www/logs/wr.pl", "-c", "/var/local/www/logs/www.conf",
     $ylog);
