split-logfile revision b45c1c292ff1fa635004ae81fa691f8cb3cdda85
867N/A#!/usr/bin/perl
369N/A# ====================================================================
369N/A# The Apache Software License, Version 1.1
369N/A#
369N/A# Copyright (c) 2000-2001 The Apache Software Foundation. All rights
369N/A# reserved.
369N/A#
369N/A# Redistribution and use in source and binary forms, with or without
369N/A# modification, are permitted provided that the following conditions
369N/A# are met:
369N/A#
369N/A# 1. Redistributions of source code must retain the above copyright
369N/A# notice, this list of conditions and the following disclaimer.
369N/A#
369N/A# 2. Redistributions in binary form must reproduce the above copyright
369N/A# notice, this list of conditions and the following disclaimer in
369N/A# the documentation and/or other materials provided with the
369N/A# distribution.
369N/A#
369N/A# 3. The end-user documentation included with the redistribution,
1368N/A# if any, must include the following acknowledgment:
369N/A# "This product includes software developed by the
369N/A# Apache Software Foundation (http://www.apache.org/)."
369N/A# Alternately, this acknowledgment may appear in the software itself,
369N/A# if and wherever such third-party acknowledgments normally appear.
369N/A#
369N/A# 4. The names "Apache" and "Apache Software Foundation" must
369N/A# not be used to endorse or promote products derived from this
844N/A# software without prior written permission. For written
844N/A# permission, please contact apache@apache.org.
369N/A#
369N/A# 5. Products derived from this software may not be called "Apache",
369N/A# nor may "Apache" appear in their name, without prior written
369N/A# permission of the Apache Software Foundation.
369N/A#
369N/A# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
867N/A# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
867N/A# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1368N/A# DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
1368N/A# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1368N/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
867N/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
867N/A# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
867N/A# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
369N/A# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
369N/A# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
369N/A# SUCH DAMAGE.
369N/A# ====================================================================
369N/A#
369N/A# This software consists of voluntary contributions made by many
369N/A# individuals on behalf of the Apache Software Foundation. For more
369N/A# information on the Apache Software Foundation, please see
369N/A# <http://www.apache.org/>.
369N/A
369N/A# This script will take a combined Web server access
369N/A# log file and break its contents into separate files.
369N/A# It assumes that the first field of each line is the
369N/A# virtual host identity (put there by "%v"), and that
369N/A# the logfiles should be named that+".log" in the current
369N/A# directory.
369N/A#
369N/A# The combined log file is read from stdin. Records read
369N/A# will be appended to any existing log files.
369N/A#
369N/A%is_open = ();
369N/A
369N/Awhile ($log_line = <STDIN>) {
369N/A #
369N/A # Get the first token from the log record; it's the
369N/A # identity of the virtual host to which the record
369N/A # applies.
369N/A #
369N/A ($vhost) = split (/\s/, $log_line);
369N/A #
369N/A # Normalize the virtual host name to all lowercase.
369N/A # If it's blank, the request was handled by the default
369N/A # server, so supply a default name. This shouldn't
369N/A # happen, but caution rocks.
369N/A #
369N/A $vhost = lc ($vhost) or "access";
369N/A #
867N/A # If the log file for this virtual host isn't opened
369N/A # yet, do it now.
369N/A #
369N/A if (! $is_open{$vhost}) {
369N/A open $vhost, ">>${vhost}.log"
369N/A or die ("Can't open ${vhost}.log");
369N/A $is_open{$vhost} = 1;
}
#
# Strip off the first token (which may be null in the
# case of the default server), and write the edited
# record to the current log file.
#
$log_line =~ s/^\S*\s+//;
printf $vhost "%s", $log_line;
}
exit 0;