#!/usr/bin/env perl # # apache-virtual-sites-l-execute # # $Id$ # postprocesses apache-virtual-sites -l output use warnings; use strict; use Getopt::Std; my ($me) = $0 =~ m#([^/]*$)#; my %opt; getopts( 'hv', \%opt ); sub ehm { $opt{v} and warn join( ' ', @_ ), "\n"; } if ( $opt{h} || !@ARGV ) { HELP_MESSAGE(); } sub HELP_MESSAGE { print STDERR <s %b" i.e. comma-separated fields: + URL + absolute logfile name + log format statement + log format specification Output: The output is the concatenation of the command's output on each of the logfiles in the input for which a LogFormat is supplied. Example: apache-virtual-sites -l /etc/httpd/conf/httpd.conf | fgrep example.com | $me -v sh -c 'accesslog-aggregate -vw -t %H -f %f %l' Note the use of sh -c to de-escape the log format specification. ZZ exit; } while () { chomp; my ( $url, $absfile, $typename, $format ) = split( /,/, $_, 4 ); next if $format !~ /"/; ehm("log file $absfile has format $format"); my @command = map { # strictly speaking this is incorrect; # to avoid problems in practice, $format must be last! $_ = replace_with_in( '%n', $typename, $_ ); $_ = replace_with_in( '%u', $url, $_ ); $_ = replace_with_in( '%l', $absfile, $_ ); $_ = replace_with_in( '%f', $format, $_ ); } @ARGV; ehm( 'executing:', @command ); system(@command); } sub replace_with_in { my ( $from, $to, $in ) = @_; join( $to, split( $from, $in, -1 ) ); }