#!/usr/local/bin/perl5 -w
#
# combine_host.pl [host prefix] > outputfile
# 
use Time::Local;
use Date::Manip;

$host = $ARGV[0];

open(FILELIST,"ls -1 $host* |");
@files = <FILELIST>;
close(FILELIST);

for ($i=0;$i<=$#files;$i++) {
    chomp($files[$i]);
#    print STDERR "$files[$i]\n";
    @fields=split('\.',$files[$i]);
    $datestamp = $fields[$#fields-1];
    $datestamp =~ s/\_/ /g;
    $datestamp =~ s/\-/:/g;
#    print STDERR "$datestamp\n";
    $date = &ParseDate($datestamp);
    if (! $date) {
	print STDERR "FAIL\n";
    }
    $timestamp{$files[$i]} = &UnixDate($date,"%s");
#    print "$timestamp{$files[$i]}\t$files[$i]\n";
}

print "\n\n";

@sorted = sort { $timestamp{$a} <=> $timestamp{$b}; } @files;

#for ($i=0;$i<=$#sorted;$i++) {
#    print "$timestamp{$sorted[$i]}\t$sorted[$i]\n";
#}

print STDERR "systeming cat of\n";
for ($i=0;$i<=$#sorted;$i++) {
    print STDERR "$sorted[$i]\n";
}

system "cat", @sorted;

