#!/usr/bin/perl -w

#### Author:  	Abbi @ Earthen Ring (US)
####		strand.osric@gmail.com
#### Version:	1.0
#			1.0 	first release

use Time::Local;

my $timechunk = shift || "";
my $file = shift || "";

if (! $timechunk || ! $file) {
	print "Usage: $0 <idle seconds before split> <log>\n";
	exit;
}

my $chunk = 1;
my $lasttime = 0;

open(FILE, $file) || die;

foreach my $line (<FILE>) {
	my $time = log2time((split(/  /, $line))[0]);
	if ($time > $lasttime + 5) {
		$chunk++;
		close(FILEOUT);
		open(FILEOUT, ">" . $file . "." . $chunk) || die;
	}
	print FILEOUT $line;
	$lasttime = $time;
}

close(FILEOUT);

sub log2time {
	my $date = shift;
	my @time = split(/[ :.\/]/, $date);
	return timegm($time[4], $time[3], $time[2], $time[1], $time[0] - 1, 2000);
}
