#! /bin/sh # daily DCC cron job # This script should be run daily or more often when there is a shortage # of disk space to run dbclean to discard and compress old checksums. # It also discards old DCC client log files. #. By default it is installed in /var/dcc/libexec. Instead of being copied # to a directory such as /etc/cron/daily on some systems, a symbolic link # should be used. # cron tab entry like this can be used: # 15 2 * * * /var/dcc/libexec/cron-dccd # It is best to choose different times for each of your DCC servers so # that your servers are not all busy cleaning their databases at once. # -x turn on debugging # -F do not follow symbolic links because they are used to share # per-user directories # -h dir override DCC home directory /var/dcc # -a args for dbclean in addition to DBCLEAN_ARGS in /var/dcc/dcc_conf # Copyright (c) 2012 by Rhyolite Software, LLC # # This agreement is not applicable to any entity which sells anti-spam # solutions to others or provides an anti-spam solution as part of a # security solution sold to other entities, or to a private network # which employs the DCC or uses data provided by operation of the DCC # but does not provide corresponding data to other users. # # Permission to use, copy, modify, and distribute this software without # changes for any purpose with or without fee is hereby granted, provided # that the above copyright notice and this permission notice appear in all # copies and any distributed versions or copies are either unchanged # or not called anything similar to "DCC" or "Distributed Checksum # Clearinghouse". # # Parties not eligible to receive a license under this agreement can # obtain a commercial license to use DCC by contacting Rhyolite Software # at sales@rhyolite.com. # # A commercial license would be for Distributed Checksum and Reputation # Clearinghouse software. That software includes additional features. This # free license for Distributed ChecksumClearinghouse Software does not in any # way grant permision to use Distributed Checksum and Reputation Clearinghouse # software # # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # Rhyolite Software DCC 1.3.152-1.85 $Revision$ # Generated automatically from cron-dccd.in by configure. exec 1>&2 /dev/null; then : else USERDIRS="$USERDIRS $DCCIFD_USERDIRS" fi fi # trim the greylist database case X"$GREY_ENABLE" in [oO][nN]) GREY_ENABLE=on ;; X) if test -n "$GREY_CLIENT_ARGS"; then GREY_ENABLE=on fi ;; esac if test -z "$GREY_SRVR_ID"; then if grep '# auto local greylist server-ID' $DCC_HOMEDIR/ids >/dev/null \ && grep '^32702[ ]' $DCC_HOMEDIR/ids >/dev/null; then GREY_SRVR_ID=32702 fi fi if test -n "$GREY_SRVR_ID" -a "$GREY_ENABLE" = on; then if $DCC_LIBEXEC/dbclean -Gon -i $GREY_SRVR_ID $GREY_DBCLEAN_ARGS; then : else # assume EX_DCC_RESTART=79 if test $? -eq 79; then eval $DCC_LOGGER \"running dbclean -S and restarting greylist server\" $DCC_LIBEXEC/dbclean -S -Gon -i $GREY_SRVR_ID $GREY_DBCLEAN_ARGS $DCC_LIBEXEC/start-grey fi fi fi # Delete old checksums from the dccd database if it seems dccd can run. # For historical reasons, SRVR_ID set and DCCD_ENABLE null # also turns on dccd. case "$DCCD_ENABLE" in [oO][fF][fF]) DCCD_ENABLE=off;; *) DCCD_ENABLE=on;; esac if test -n "$SRVR_ID" -a "$DCCD_ENABLE" = on; then if $DCC_LIBEXEC/dbclean -i $SRVR_ID $SADDR $DBCLEAN_ARGS; then : else # assume EX_DCC_RESTART=79 if test $? -eq 79; then eval $DCC_LOGGER \"running dbclean -S and restarting DCC server\" $DCC_LIBEXEC/dbclean -S -i $SRVR_ID $SADDR $DBCLEAN_ARGS $DCC_LIBEXEC/start-dccd fi fi fi # Remove old dccm and dccifd log files. if test -n "$DBCLEAN_LOGDAYS" -a -n "$LOGDIRS$USERDIRS"; then ( find $LOGDIRS $USERDIRS $FOLLOW -type f \ \( \( -name 'msg.*' -mtime +$DBCLEAN_LOGDAYS \) \ -o \( -name 'tmp.*' -mtime +1 \) \) -print \ | /usr/bin/xargs -n1000 /bin/rm find $LOGDIRS $USERDIRS $FOLLOW -depth -type d \ \( -name '[0-9]' -o -name '[0-9][0-9]' \ -o -name '[0-9][0-9][0-9]' \) -print \ | /usr/bin/xargs -n1000 /bin/rmdir ) 2>&1 | grep -v 'No such file or directory' \ | grep -v 'Directory not empty' fi # Notify users about new log files. # The file $DCC_LIBEXEC/webuser-notify must be a script that will send # a suitable message. See the example in the cgi-bin directory. if test -n "$USERDIRS" -a -x $DCC_LIBEXEC/webuser-notify; then for DIR in $USERDIRS; do MARKER=$DIR/notify.marker if test -r $MARKER; then NEWER="-newer $MARKER" else NEWER= fi rm -f $MARKER.new touch $MARKER.new # Find usernames with a pending message or with a new but not newer # than new log file. Avoid newer than new files to ensure we # generate at most one notification per log file. (cd $DIR; find . $FOLLOW -type f \( -name notify.pending \ -o \( $NEWER -name 'msg.*' \) \) \ ! -newer $MARKER.new -print ) \ | sed -n -e 's@\./\(.*\)/log/msg\..*@\1@p' \ -e 's@\./\(.*\)/log/[0-9/]*/msg\..*@\1@p' \ -e 's@\./\(.*\)/notify.pending$@\1@p' \ | sort -u \ | $DCC_LIBEXEC/webuser-notify $DEBUG -d "$DIR" mv -f $MARKER.new $MARKER done fi # encourage local DCC clients to switch back /usr/local/bin/cdcc -q rtt >/dev/null 2>&1