Hallo,
Am Thu, 31 Mar 2011, Lentes, Bernd schrieb:
[..]
#!/bin/bash
[..]
not_compress=(`cat aktuelle_mitarbeiter_idg_2.txt`)
# geht auch ohne Leerzeichen in der Datei, funktioniert auch mit \n
Da du bash verwendest, nimm lieber
IFS=$'\n'
not_compress=( $(< aktuelle_mitarbeiter_idg_2.txt) )
# echo ${not_compress[*]}
# echo "Anzahl der Elemente in array not_compress: ${#not_compress[*]}"
count_not_compress=${#not_compress[*]}
[*] solltest du meiden.
count_not_compress=${#not_compress[@]}
all=(`cat all_homedirs_2.txt`)
# echo ${all[*]}
# echo "Anzahl der Elemente in array all: ${#all[*]}"
count_all=${#all[*]}
Dito.
all=( $(< all_homedirs_2.txt) )
count_all=${#all[@]}
# for ((i=0;i<count_not_compress;i++))
# do
# echo ${not_compress[i]}
# done
# for ((i=0;i<count_all;i++))
# do
# echo ${all[i]}
# done
for ((a=0;a<count_all;a++))
do
# echo ${all[a]}
for ((n=0;n<count_not_compress;n++))
do
if [ "${not_compress[n]}" = "${all[a]}" ]
then
# echo "Päärchen gefunden: ${not_compress[n]} = ${all[a]}, muss *nicht*
komprimiert werden"
break
fi
if [ $n -eq $[$count_not_compress-1] ]
then
:
echo "${all[a]} muss verschoben werden !"
mv -v ${all[a]} ehemalige
fi
done
done
Und der Rest schreit nach ner Programmiersprache, die Hashes kann.
====
#!/usr/bin/perl -ws
use strict;
my $homedir = "/mnt/nas/home";
my $aktuelle_datei = "aktuelle_mitarbeiter_idg_2.txt";
my $all_homes_datei = "all_homedirs_2.txt";
no warnings 'once';
my $dry_run = $::n || 0;
my $verbose = $::v || 0;
use warnings 'once';
### mein Standard system() wrapper zur ordentlichen Fehlerbehandlung,
### samt moeglichem "dry-run", wenn mit Option '-n' aufgerufen
sub runcmd {
my $ret = 0;
if( ! $dry_run ) {
system(@_);
$ret = $?;
if( $ret == -1 ) {
print STDERR "failed to execute: $!\n";
} elsif ($ret & 127) {
printf STDERR "\nchild died with signal %d, %s coredump\n",
($ret & 127), ($ret & 128) ? "with coredump" : "";
}
} else {
print "\nWould run: ", join(" ", @_), "\n";
}
return $ret == 0;
}
sub readfile {
my $file = shift;
open(F, "<", $file) or die "cannot read $file: $!\n";
my @lines = <F>;
chomp(@lines);
close(F) or die "$!\n";
return @lines;
}
chdir($homedir) or die "Cannot change to $homedir!\n";
-d "./ehemalige/" or die "Verzeichnis 'ehemalige' existiert
nicht!\n";
my @not_compress = readfile($aktuelle_datei);
my @all_homes = readfile($all_homes_datei);
my %dont_compress;
map { if(m/\S/) { $dont_compress{$_} = 1; } } @not_compress;
foreach(@all_homes) {
if( defined($dont_compress{$_}) ) {
print "$_ kann bleiben\n";
} else {
# print "$_ muss verschoben werden\n";
runcmd("mv", "-iv", $_, "./ehemalige/");
}
}
====
Wie du siehst, ist die eigentliche Programmlogik (ab der 'map' Zeile)
sehr simpel.
Jetzt grübele ich über der Komprimierung.
afio. Komprimiert Dateiweise.
cd ./ehemalige/
for dir in *; do
find "$dir" -depth -print0 | afio -o -0axZv "${dir}.afio"
done
Siehe man afio für weitere Optionen (z.B. um schon komprimiertes nicht
nochmal zu komprimieren, für verify, '-P bzip2' z.B. um mit bzip statt
gzip zu komprimieren.
HTH,
-dnh
--
So Linus, what are we doing tonight?
The same thing we do every night Tux. Try to take over the world!
--
Um die Liste abzubestellen, schicken Sie eine Mail an:
opensuse-de+unsubscribe(a)opensuse.org
Um eine Liste aller verfuegbaren Kommandos zu bekommen, schicken
Sie eine Mail an: opensuse-de+help(a)opensuse.org