in reply to Calling functions
It works properly every time, that is, if it is run apart from the proceeding functions. Here is gen_stats():sub split_logfile { # As adapted from the split-logile perl script from the Apache gro +up my($vhost); my($log_line); my(%is_open); open(LOG, "<$access_log") or die("Cannot open $access_log for processing: $!"); while($log_line = <LOG>) { ($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"); }
The files that split_logfile() creates when it's run alone must have at least one log entry in them or they're simply not created. If I run it in conjunction with gen_stats(), several files are created without a single entry in them (zero length, as though the function simply doesn't finish). I've looked it over several times, yet I cannot seem to figure it out. If it's something simple or I'm doing something wrong, please keep in mind that I am a Perl beginner. :)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", "2 +0", "-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 r +unning stats for # that particular web. if ( -e "$stats_dir/$domain" ) { system($webalizer, "-q", "-D", $work_dir."/dns_cache.d +b", "-N", "20", "-n", $domain, "-o", $stats_dir."/".$domain, $work +_dir."/".$log); } else { print "Stats directory for $domain doesn't exist. +\n"; } } } closedir WORKDIR; }
Thanks again.
Brendon
|
---|
Replies are listed 'Best First'. | |
---|---|
(tye)Re: Calling functions
by tye (Sage) on Mar 23, 2001 at 02:59 UTC | |
Re: Re: Calling functions
by indigo (Scribe) on Mar 23, 2001 at 02:51 UTC | |
by tye (Sage) on Mar 23, 2001 at 03:09 UTC |