sub split_logfile { # As adapted from the split-logile perl script from the Apache group my($vhost); my($log_line); my(%is_open); open(LOG, "<$access_log") or die("Cannot open $access_log for processing: $!"); while($log_line = ) { ($vhost) = split(/\s/, $log_line); $vhost = lc($vhost); if (! $is_open{$vhost}) { open $vhost, ">>$work_dir/${vhost}.log" or die ("Cannot open ${vhost}.log: $!"); $is_open{$vhost} = 1; } $log_line =~ s/^\S*\s+//; printf($vhost "%s", $log_line); } print("DONE\n"); } #### sub gen_stats { my($log); my($domain); # Generate stats for the entire server (server wide) system($webalizer, "-q", "-D", $work_dir."/dns_cache.db", "-N", "20", "-n", $server_hostname, "-o", $server_log_dir, $access_log); opendir(WORKDIR, $work_dir) or die "Could not open $work_dir: $!\n"; while (defined($log = readdir(WORKDIR))) { # If the file isn't . or .. then strip off the .log portion to get just the host # + domain. Run webalizer using log file. if ($log !~ /^\.\.?$/ and $log !~ /dns_cache\.db/) { ($domain) = split(/\.log/, $log); # IF the web stats directory doesn't exist, don't bother running stats for # that particular web. if ( -e "$stats_dir/$domain" ) { system($webalizer, "-q", "-D", $work_dir."/dns_cache.db", "-N", "20", "-n", $domain, "-o", $stats_dir."/".$domain, $work_dir."/".$log); } else { print "Stats directory for $domain doesn't exist.\n"; } } } closedir WORKDIR; }