logmanager/logcleaner

40 lines
744 B
Plaintext
Raw Normal View History

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 [...]]
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
}
while getopts hina: o
2011-02-23 15:39:35 +01:00
do
case "$o" in
-) 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
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