2011-02-23 15:39:35 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
a=60
|
|
|
|
n=
|
|
|
|
|
|
|
|
help() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage: `basename "$0"` -h | [-i|-n] [-a AGE] DIR [DIR [...]]
|
2013-01-16 21:26:17 +01:00
|
|
|
Looks for all files in DIR/archive, which are older than AGE and removes these.
|
|
|
|
-a AGE Maximal age of file in days to hold (std: $a).
|
|
|
|
-n Dummy mode. Shows files to remove, if not in dummy mode.
|
|
|
|
-i Asks to remove (see also rm).
|
2011-02-23 15:39:35 +01:00
|
|
|
EOF
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:29:29 +02:00
|
|
|
while getopts hina: o
|
2011-02-23 15:39:35 +01:00
|
|
|
do
|
|
|
|
case "$o" in
|
2012-07-18 16:29:29 +02:00
|
|
|
-) break ;;
|
|
|
|
h) help ;;
|
|
|
|
a) a="$OPTARG" ; shift ;;
|
|
|
|
i) i=-i ;;
|
|
|
|
n) n=echo ;;
|
2012-07-30 12:02:42 +02:00
|
|
|
*) echo "Unknown Option: $o" >&2
|
|
|
|
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
|
|
|
|
|
|
|
[ 0 -lt $# ] || help
|
|
|
|
[ X = X"$a" ] || a="-mtime +$a"
|
|
|
|
|
|
|
|
for d
|
|
|
|
do
|
|
|
|
find "$d" -name archive -type d -exec sh -c '
|
|
|
|
find "$1" -type f '"$a"' -exec '"$n"' rm '"$i"' -- "{}" \;' -- '{}' \;
|
|
|
|
done
|