|
Linux & co
|
|
Written by lukas
|
|
Thursday, 11 November 2010 13:46 |
|
There are no translations available.
#!/usr/bin/perl
# $Id: split-logs,v 1.1 2008/10/09 08:59:44 cvsoernii Exp $
# based on apache split-logs
%is_open = ();
while ($log_line = <STDIN>) {
# "-" is the splitting char, change as needed
($vhost) = split (/-/, $log_line);
# if the log line does NOT match this date format
# then appned it to previous log file
if ($log_line !~ /^[0-9]{2}.[0-9]{2}.[0-9]{4}-/)
{
$vhost = $oldhost;
}
if (! $is_open{$vhost}) {
open $vhost, ">>${vhost}.log"
or die ("Can't open ${vhost}.log");
$is_open{$vhost} = 1;
}
printf $vhost "%s", $log_line;
$oldhost = $vhost;
}
exit 0;
|
|
Last Updated on Thursday, 11 November 2010 13:48 |