2012-07-30 11:46:57 +02:00
|
|
|
#!/bin/sh
|
2011-02-23 15:39:35 +01:00
|
|
|
|
|
|
|
e='*.log'
|
|
|
|
i=
|
|
|
|
n=
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:29:29 +02:00
|
|
|
while getopts hnie: o
|
2011-02-23 15:39:35 +01:00
|
|
|
do
|
|
|
|
case "$o" in
|
2012-07-18 16:29:29 +02:00
|
|
|
h) help ;;
|
|
|
|
e) e="$OPTARG" ;;
|
|
|
|
n) n=echo ;;
|
|
|
|
i) i=-i ;;
|
|
|
|
*) help ;;
|
2011-02-23 15:39:35 +01:00
|
|
|
esac
|
|
|
|
done
|
2012-07-30 11:46:57 +02:00
|
|
|
shift `expr $OPTIND - 1`
|
2011-02-23 15:39:35 +01:00
|
|
|
|
2012-07-30 13:55:52 +02:00
|
|
|
if fuser "$0" >/dev/null 2>/dev/null
|
2012-07-30 12:24:51 +02:00
|
|
|
then :
|
|
|
|
else
|
|
|
|
echo "fuser not found or does not work! logarchiver won't to destroy any files, so exit."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-07-30 12:02:42 +02:00
|
|
|
if [ 0 -ge $# ]
|
2012-07-18 16:29:29 +02:00
|
|
|
then
|
|
|
|
echo "Error: DIR expected"
|
|
|
|
help
|
|
|
|
fi
|
2011-02-23 15:39:35 +01:00
|
|
|
|
|
|
|
for d
|
|
|
|
do
|
2012-07-18 16:29:29 +02:00
|
|
|
find "${d}" -name archive -prune -o -type f \( -name "${e}" \) -exec sh -c '
|
2011-02-23 15:39:35 +01:00
|
|
|
if [ X = "X`fuser "$1" 2>/dev/null`" ]
|
|
|
|
then
|
|
|
|
a="`dirname "$1"`/archive"
|
2012-07-18 16:29:29 +02:00
|
|
|
'"${n}"' mkdir -p -- "$a"
|
|
|
|
'"${n}"' mv '$i' -- "$1" "$a"
|
2011-02-23 15:39:35 +01:00
|
|
|
fi ' -- '{}' \;
|
|
|
|
done
|