myclog-join.pl c:/path/to/files 080505

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl -w
# perl5.8 adapted
# perl myclog-join.pl c:/path/to/files 080505
# 21.03.2008
use strict;
use POSIX qw(strftime);
use File::Basename;
use File::stat;
use lib dirname($0);
use paUtil;
# not enough parameters
if ($#ARGV != 1) { print "Achtung!\n"; exit 10; }
my $spath = $ARGV[0];
#my $today = strftime("%d/%m/%Y %H:%M:%S", localtime()); # (26/02/2008 10:42:33)
my $today = strftime("%d/%m/%Y", localtime());
#my $today_ = strftime("%y%m%d", localtime());
if ($ARGV[1]) { $today = $ARGV[1]; }
my @list = paUtil::get_dir_contents($spath);
@list = grep(/^$today\_/, @list);
my $ofile = "";
if ($list[0] =~ /($today)\_(\d{4})\s(.+\.log)/is) {
$ofile = $1 . " " . $3;
}
my $i = 0;
print "* writing \"$ofile\"..." . "\n";
open(OF, ">"."$spath\\$ofile") or die "!: $!";
foreach my $sfile (@list) {
my $sa = stat("$spath\\$sfile");
print " \"$sfile\"" . "\n";
if ($sfile ne $list[0]) {
my $sb = stat("$spath\\$list[$i-1]");
if ($sa->size > $sb->size) {
print $sfile . ", " . $sa->size . " > " . $list[$i-1] . ", " . $sb->size ."\n";
next;
}
} else { $i = 0; }
open(IF, "<"."$spath\\$sfile") || die "! can't open file: $!";
while (<IF>) {
#chomp;
print OF $_;
}
close(IF);
$i++;
}
close(OF);
print "* done.\n";
exit 0;