use Data::Dumper;
use POSIX;
use File::Copy;
+use Sys::Hostname;
use Carp qw(:DEFAULT cluck);
my $class = ref($invocant) || $invocant;
my $uid = $>;
my ( $gid ) = $) =~ /^(\d+)/;
- my ( $res, $cmd );
+ my ( $res, $cmd, $t, $domain, $host );
my $self = {
test => 0,
$self->{'c'} = $conf;
+ # Ermittlung aller Platzhalter fuer olddir-Sachen ...
+ $self->{'template'} = {};
+
+ # Host- und Domainname ...
+ $t = hostname();
+ $domain = "";
+ $host = $t;
+ if ( $t =~ /^([^\.]+)\.(.*)/ ) {
+ $host = $1;
+ $domain = $2;
+ }
+ $self->{'template'}{'nodename'} = $host;
+ $self->{'template'}{'domain'} = $domain;
+
+ # Plattform
+ $t = `uname -i`;
+ chomp $t;
+ $self->{'template'}{'platform'} = $t;
+
+ # Prozessor
+ $t = `uname -p`;
+ chomp $t;
+ $self->{'template'}{'isa'} = $t;
+
+ # OS-Release
+ $t = `uname -r`;
+ chomp $t;
+ $self->{'template'}{'release'} = $t;
+
+ # Maschinen-Version
+ $t = `uname -m`;
+ chomp $t;
+ $self->{'template'}{'machine'} = $t;
+
#return undef unless $self->check_state_file();
return $res;
my $p = verbose() ? __PACKAGE__ . "::create_olddir(): " : "";
my ( $dir, $adir, $mode, $owner, $group, $olddir );
- my ( $pmode, $puid, $pgid );
+ my ( $pmode, $puid, $pgid, $basename, $t );
my ( @Dirs, @Stats );
my $uid = $>;
my ( $gid ) = $) =~ /^(\d+)/;
$olddir = $o->{'dirname'};
}
- unless ( $olddir =~ m#^/# ) {
- ( $dir ) = $file =~ m#(.*)/[^/]*$#;
- $olddir = $dir . "/" . $olddir;
+ # Ersetzung aller Platzhalter in Olddir-Angabe
+
+ unless ( ( $dir, $basename ) = $file =~ m#(.*)/([^/]*)$# ) {
+ warn $p . "Ungueltiger Logdateiname: '$file'\n";
+ return undef;
}
+
+ # Verzeichnisname ...
+ $olddir =~ s/(?:\${dirname}|\$dirname(?![a-zA-Z0-9_]))/$dir/g;
+
+ # Basename ...
+ $olddir =~ s/(?:\${basename}|\$basename(?![a-zA-Z0-9_]))/$basename/g;
+
+ # Nodename
+ $t = $self->{'template'}{'nodename'};
+ $olddir =~ s/(?:\${nodename}|\$nodename(?![a-zA-Z0-9_]))/$t/g;
+
+ # Domain
+ $t = $self->{'template'}{'domain'};
+ $olddir =~ s/(?:\${domain}|\$domain(?![a-zA-Z0-9_]))/$t/g;
+
+ # Platform
+ $t = $self->{'template'}{'platform'};
+ $olddir =~ s/(?:\${platform}|\$platform(?![a-zA-Z0-9_]))/$t/g;
+
+ # Isa
+ $t = $self->{'template'}{'isa'};
+ $olddir =~ s/(?:\${isa}|\$isa(?![a-zA-Z0-9_]))/$t/g;
+
+ # Release
+ $t = $self->{'template'}{'release'};
+ $olddir =~ s/(?:\${release}|\$release(?![a-zA-Z0-9_]))/$t/g;
+
+ # Machine
+ $t = $self->{'template'}{'machine'};
+ $olddir =~ s/(?:\${machine}|\$machine(?![a-zA-Z0-9_]))/$t/g;
+
+ $olddir = $dir . "/" . $olddir unless $olddir =~ m#^/#;
+
$o->{'expanded'} = $olddir;
print $p . "Olddir ist jetzt: '$olddir'.\n" if verbose() > 1;
# Rotationsziel gibt's nicht, okay, raus hier
return $res unless -f $t;
+ print $p . "Rotationsziel '$t' gibt's schon, ermittle zyklische Rotationen ...\n" if verbose() > 2;
# restliche Rotationen festlegen ...
while ( -f $t ) {
$t_new = $target . "." . $i . $ext;
+ print $p . "Zyklische Rotation '$t' -> '$t_new'.\n" if verbose() > 3;
$pair = { 'from' => $t,
'to' => $t_new,
};
unshift @{$res->{'move'}}, $pair;
+ $t = $t_new;
$i++;
}
print $p . "Struktur von '$file': " . " " . Dumper( $f ) if verbose() > 2;
- my ( $nr, $dir, $basename, $target, $pattern );
+ my ( $nr, $dir, $basename, $target, $pattern, $t );
unless ( $f ) {
carp( $p . "Keine gueltige Logdatei uebergeben!\n" );
return undef;
}
- $target = $f->{'olddir'}{'expanded'} ? $f->{'olddir'}{'expanded'} . "/" . $basename : $file;
+ $dir = $f->{'olddir'}{'expanded'} if $f->{'olddir'}{'expanded'};
+ $target = $dir . "/" . $basename;
if ( $f->{'dateext'} ) {
$pattern = $f->{'datepattern'};
print $p . "Verwende Datumsersetzung '$pattern' fuer '$file'.\n" if verbose() > 1;