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