logmanager/logmanager

80 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
archiver=`dirname "$0"`/logarchiver
rotator=`dirname "$0"`/logrotator
compressor=`dirname "$0"`/logcompressor
cleaner=`dirname "$0"`/logcleaner
cmd=
help() {
cat <<EOF
`basename "$0"` -h | [-a EXE] [-z EXE] [-C EXE] -c CONF
-c CONF Konfigurationsdatei
-a EXE Archiver (std: ./logarchiver)
-z EXE Compressor (std: ./logcompressor)
-C EXE Cleaner (std: ./logcleaner)
-n Gibt die Befehle aus, die Ausgefuehrt werden wuerden
-N Fuehrt die Unterprozesse mit -n aus
EOF
exit
}
with_n() {
__cmd=$1
shift
echo "$__cmd" -n "$@"
"$__cmd" -n "$@"
}
while getopts hc:a:r:z:C:nN o
do
case "$o" in
h) help ;;
c) c="$OPTARG" ;;
a) archiver="$OPTARG" ;;
r) rotator="$OPTARG" ;;
z) compressor="$OPTARG" ;;
C) cleaner="$OPTARG" ;;
n) cmd=echo ;;
N) cmd=with_n ;;
*) help ;;
esac
done
shift `expr $OPTIND - 1`
for n in "$c" ./lmtab "$HOME/.lmtab" /etc/lmtab
do
if [ -f "$n" ]
then
c=$n
break
fi
done
if [ ! -r "$c" ]
then
echo "No config found." >&2
exit 1
fi
eval `sed -ne '
s/#.*//;s/'\''/'"'\\\\\''"'/g;
s/\${\([a-zA-Z][0-9a-zA-Z_]*\)}/'\''"$\1"'\''/;
s/^\([a-zA-Z_][0-9a-zA-Z_]*\)=\(.*\)/\1='\''\2'\''/p
' < "$c"`
# Format: Verzeichnis [Ausdruck[/Ausdruck[,...]] [Aufbewahrungszeit]]
# Verzeichnisse duerfen nur einmalig Vorkommen
sed -ne 's/#.*//;s/^[a-zA-Z_][0-9a-zA-Z_]*=.*//;/\//p' "$c" | while read dir exp age opts
do
[ X = "X$age" ] || age="-a$age"
while [ ! "X." = "X${exp}" ]
do
e="`basename "${exp}"`"
exp="`dirname "${exp}"`"
$cmd $archiver -e "$e" -- "$dir"
done
$cmd $compressor -- "$dir"
[ 0 = "$age" ] || $cmd $cleaner "$age" -- "$dir"
done