#!/usr/bin/perl # -*- perl -*- @(#) $Id: webalize,v 1.3 2000/06/26 20:04:11 root Exp $ # # $Revision: 1.3 $ # $Date: 2000/06/26 20:04:11 $ # $Author: root $ # $Locker: $ # $RCSfile: webalize,v $ # $State: Exp $ # $Source: /opt/webalizer/bin/RCS/webalize,v $ require 5.005; use strict; use DBI; umask 002; my @dom_list = ''; my $dom_restrict_query = ''; if ( scalar(@ARGV) > 0 ) { @dom_list = @ARGV; $dom_restrict_query = " and domain in ('" . join("','", @dom_list) . "') "; } my $prog_name = $0; # my $log_basedir = '/webstat-filer/NT/'; my $log_basedir = '/webstat/NT/'; my $log_dir = ''; my $syscmd_webalizer_wrapper = '/opt/webalizer/bin/webalizer-wrapper'; # The parse2ncsa command takes a directory name as a parameter, # and parses all of the logs in that directory in chronological # order, converting to NCSA format wherever necessary. It sends # the NCSA common/combined log format to STDOUT. my $syscmd_parse2ncsa = '/opt/webalizer/bin/parse2ncsa'; chdir $log_dir or die "Could not change to $log_dir"; my $domain; my $webserver; my $w3svc; my $ip_addr; my $line; my $driver = 'mysql'; my $database = 'webstat'; my $table = 'sites'; my $user = 'statadmin'; my $password = 'statsrus'; my $dbh; my $dsn = "DBI:$driver:$database"; my $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1, AutoC +ommit => 1}); my $query = "select domain, server_type, server_name, log_code, log_lo +cation from sites " . " where active = 1 " . $dom_restrict_query # gets domains from command line . " order by priority "; my $sth = $dbh->prepare($query); $sth->execute(); my $res_hashref; while (defined ( $res_hashref = $sth->fetchrow_hashref )) { # variables are # $$res_hashref{'domain'} # domain name for stats # $$res_hashref{'server_name'} # server such as "ntpub1" # $$res_hashref{'log_code'} # W3SVC number # change ARGV[0] so that current info will appear in a "ps" listin +g $0 = sprintf ("%s - processing %s from %s/%s", $prog_name, $$res_hashref{'domain'}, $$res_hashref{'server_name'}, $$res_hashref{'log_code'}); if ( $$res_hashref{'server_type'} eq 'iis4.0' or $$res_hashref{'se +rver_type'} eq 'iis5.0' ) { #next unless $$res_hashref{'log_code'}; my $log_dir = join('/', $log_basedir, $$res_hashref{'server_name'}, $$res_hashref{'log_code'}); open(NCSA_STREAM,"$syscmd_parse2ncsa $log_dir $$res_hashref{'domai +n'} |") or next; } elsif ( $$res_hashref{'server_type'} eq 'apache' ) { my $log_file = $$res_hashref{'log_location'}; open(NCSA_STREAM,"<$log_file"); } else # not iis4.0/iis5.0 nor apache { next; } open(WEBALIZER, "|$syscmd_webalizer_wrapper $$res_hashref{'domain' +}") or next; while (defined ($line = <NCSA_STREAM>)) { $line =~ tr/\000//d; # remove ASCII nulls that NT IIS puts in log + files print WEBALIZER $line while defined ($line = <NCSA_STREAM>); } close(NCSA_STREAM); close(WEBALIZER); } $dbh->disconnect;
In reply to Efficiency by tekniko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |