Well here's the split_logs() function (this is code that I copied/ modified from the splitlogs script that is included in the Apache source):
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"); }
It works properly every time, that is, if it is run apart from the proceeding functions. Here is gen_stats():
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; }
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. :)

Thanks again.

Brendon


In reply to Re: Calling functions by brendonc
in thread Calling functions by brendonc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.