File cleanDCC.cron of Package dcc
#!/bin/sh
#
# copyright (c) 2012 Stefan Jakobs
# Author: Stefan Jakobs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# daily DCC cron job
#
# This script should be run daily to discard old DCC client log files.
# It accepts two arguments: -h two specify an other than the default
# home directory (/var/lib/dcc/). And -f which forces the script to
# follow symlinks, when it is removing old log files.
#
#
FOLLOW=
DCC_HOMEDIR=/var/lib/dcc
DCC_CONFIG=$DCC_HOMEDIR/dcc_conf
LOGGER_TAG=dccifd.cron
# check the args
while getopts "fh:" c; do
case $c in
h) DCC_HOMEDIR=$OPTARG ;;
f) FOLLOW="-L" ;;
*) echo "`basename $0`: [-f] -h homedir]" ;;
esac
done
# Check existence of the needed config file
test -r $DCC_CONFIG || { echo "$DCC_CONFIG not installed"; exit 6 ; }
# Read config
. $DCC_CONFIG
DCC_LOGGER="logger -p $DCC_ERROR_LOG_FACILITY -t $LOGGER_TAG"
# make the paths absolute and trim the per day/hour/minute business
DCCIFD_LOGDIR=`echo $DCCIFD_LOGDIR \
| sed -e "s@^[DHM]?@@" -e "s@^[^/]@$DCC_HOMEDIR/&@"`
DCCIFD_USERDIRS=`echo $DCCIFD_USERDIRS \
| sed -e "s@^[^/]@$DCC_HOMEDIR/&@"`
LOGDIRS=
if [ "$LOGDIRS" != "$DCCIFD_LOGDIR" ] && [ -n "$DCCIFD_LOGDIR" ] \
&& [ -d "$DCCIFD_LOGDIR" ] ; then
LOGDIRS=$DCCIFD_LOGDIR
fi
USERDIRS=
if [ -n "$DCCIFD_USERDIRS" ] && [ -d "$DCCIFD_USERDIRS" ] ; then
USERDIRS=$DCCIFD_USERDIRS
fi
# Remove old dccifd log files.
if [ -n "$DBCLEAN_LOGDAYS" ] && [ -n "$LOGDIRS$USERDIRS" ]; then
find $LOGDIRS $USERDIRS $FOLLOW -type f -name 'msg.*' \
-mtime +$DBCLEAN_LOGDAYS -exec rm '{}' \;
find $LOGDIRS $USERDIRS $FOLLOW -depth -type d -mtime +1 \( \
-name '[0-9]' -o -name '[0-9][0-9]' -o \
-name '[0-9][0-9][0-9]' \) -exec rmdir '{}' \;
fi
# log success
eval $DCC_LOGGER "old DCC client log files removed"