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
#!/usr/bin/perl -w
########################################
# Modules
use strict; # parameter Definition before use them
use File::Copy;
use DateTime; # Libary for Date operation
#######################################
# Parameter Definition
my ($ct,$idx,$idx2,$idx3,$numbers,$inPut,$outPut); # counter parameter
my $tstamp = DateTime->now->set_time_zone('Europe/Berlin'); # Find the Timestamp
my $mydate = $tstamp->ymd;
my $folder = "./workingFolder";
my $OutFolder = "./workingFolder/ReadyLogs/";
my $preFix = "server.log";
my (@filelist,@lines);
###########################
# Main
system("clear");
@filelist = glob($folder.'/server.log.*');
#print join("\n", @filelist,"\n");
rename($folder."/server.log",$folder."/01.log");
$idx = 11;
$idx2 = $idx-1;
for($ct=1;$ct<=10;$ct++){
# print `pwd`; # Output working directory
$idx =sprintf("%02d",$idx); # Put Zero in Front
$inPut =$folder."/".$preFix.".".$idx2;
$outPut =$folder."/".$idx.".log";
# print "Input: $inPut, Output: $outPut \n";
rename($inPut,$outPut) || die "Error during Rename: $!";
$idx--;
$idx2--;
}
for($ct=11;$ct>0;$ct--){
open(INFile,"<",$folder."/".$ct.".log");
open(OFile,">>",$OutFolder."/".$mydate."-ServerMessages.log");
@lines=<INFile>;
print OFile @lines;
close(INFile);
}
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
#!/usr/bin/perl use strict; use warnings; use DateTime; my $folder = "./workingFolder/"; my $OutFolder = "./workingFolder/ReadyLogs/"; my $preFix = "server.log"; # LogDateiNamen holen und Liste sortieren my @logs= map {$_->[1]} sort {$a->[0] <=> $b->[0]} map {[/(\d+)$/?$1:0,$_]} glob($folder.$preFix.'*'); # Logs umbenennen # neue Namen merken my @to_join; my $count=0; for my $old (@logs) { my $new = sprintf($folder."%02d.log",$count++); rename($old,$new) or die qq(Error during Rename "$old" => "$new": $!); push(@to_join,$new); } # BackupLog erzeugen my $mydate = DateTime->now->set_time_zone('Europe/Berlin')->ymd; # Find the Timestamp my $outfile=$OutFolder.$mydate."-ServerMessages.log"; open(my $ofh, '>', $outfile) or die qq(Error during Open "$outfile": $!); for my $file (@to_join) { open(my $ifh, '<', $file) or die qq(Error during Open "$file": $!); # langsam aber Speicher schonend # kopiere Zeile für Zeile print $ofh $_ while( <$ifh> ); close($ifh); } close($ofh); # lösche die umbenannten Logs # ansonsten gibt es Probleme beim nächsten Backup unlink(@to_join);