2011-02-23 15:39:35 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
e='*.log'
|
|
|
|
i=
|
|
|
|
n=
|
|
|
|
p=gzip
|
|
|
|
|
|
|
|
help() {
|
|
|
|
cat <<EOF
|
|
|
|
`basename "$0"` -h | [-i|-n] [-e EXP] DIR [DIR [...]]
|
|
|
|
Dursucht DIR und dessen Unterverzeichnisse nach Dateien und verschiebt alle,
|
|
|
|
die auf den Ausdruck EXP passen nach DIR/archive.
|
|
|
|
-e EXP Ausdruck, der gefunden werden soll (std: "$e")
|
|
|
|
-n Trockenlauf: Zeigt nur die Dateinamen an.
|
|
|
|
-i Fragt nach (siehe mv)
|
|
|
|
EOF
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
[ 0 -lt $# ] || help
|
|
|
|
x=`getopt hnie: "$@"` || exit 1
|
|
|
|
eval set -- $x
|
|
|
|
|
|
|
|
while [ 0 -lt $# ]
|
|
|
|
do
|
|
|
|
o=$1
|
|
|
|
shift
|
|
|
|
case "$o" in
|
|
|
|
--) break ;;
|
|
|
|
-h) help ;;
|
2012-07-11 13:33:50 +02:00
|
|
|
-e) e="$1" ; shift ;;
|
2011-02-23 15:39:35 +01:00
|
|
|
-n) n=echo ;;
|
|
|
|
-i) i=-i ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ 0 -lt $# ] || help
|
|
|
|
|
|
|
|
for d
|
|
|
|
do
|
|
|
|
find "$d" -name archive -prune -o -type f \( -name "${e}" \) -exec sh -c '
|
|
|
|
if [ X = "X`fuser "$1" 2>/dev/null`" ]
|
|
|
|
then
|
|
|
|
a="`dirname "$1"`/archive"
|
|
|
|
'"$n"' mkdir -p -- "$a"
|
|
|
|
'"$n"' mv '$i' -- "$1" "$a"
|
|
|
|
fi ' -- '{}' \;
|
|
|
|
done
|