logmanager/logcleaner

40 lines
744 B
Bash
Executable File

#!/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).
EOF
exit
}
while getopts hina: o
do
case "$o" in
-) break ;;
h) help ;;
a) a="$OPTARG" ; shift ;;
i) i=-i ;;
n) n=echo ;;
*) echo "Unknown Option: $o" >&2
help
;;
esac
done
shift `expr $OPTIND - 1`
[ 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