Back in Oct'08 David Stiller posted a nice script for cleaning up
graylist trees. Unfortunately, it doesn't work as well as it might with
v4.0 graylist trees, leaving empty directories behind.
I've taken the liberty to use it as a base for a new script I've written
for v4 (and v3) spamdyke graylists. The attached qtp-prune-graylist
script is part of the qmailtoaster-plus package
(http://qtp.qmailtoaster.com). The script can be obtained there on its
own without having to install the whole QTP package by browsing the svn
repository, and selecting "Original format" at the bottom of the page.
It can be run stand alone, and requires only a spamdyke configuration
file to operate.
The script obtains the graylist location and duration parameters from
the /etc/spamdyke/spamdyke.conf file by default. If you have a spamdyke
configuration file in another location, simply edit the script to point
to that location. If you specify these configuration parameters in
spamdyke's command line, you'll need to modify the script appropriately.
The script handles any number of domains and accounts. A recent run on a
host that had been running spamdyke v3.x for quite a while produced:
qtp-prune-graylist total - 17 domains processed
qtp-prune-graylist total - 1134404 entries found
qtp-prune-graylist total - 1128058 entries removed
qtp-prune-graylist total - 0 empty directories removed
qtp-prune-graylist total - 6740 graylisting entries remain
This host had run out of inodes before the script was run. Afterwards
12% of inodes were in use.
Counts by domain are shown as the script runs. There is an -s flag
available for silent running (think cron).
You'll probably notice that after running the script, the --config-test
option of spamdyke runs a bit faster, as it walks the entire graylist tree.
There is no option for trial run like in the former script. That seemed
like a waste to me.
Please use the ticket system provided at http://qtp.qmailtoaster.com to
report any bugs or make any enhancement requests you might have.
--
-Eric 'shubes'
#!/bin/bash
#
# Copyright (C) 2010 Eric Shubert <e...@shubes.net>
#
# This script removes old/expired entries in spamdyke's graylist tree.
#
# Original script written by David Stiller <>, posted on the spamdyke list.
# Enhanced by shubes to obtain parameters from spamdyke configuration,
# and do a more thorough job of pruning.
#
#########################################################################
# change log
# 01/26/10 shubes - created from David Stiller's greylist-clean.sh script
#########################################################################
# This should be the only thing you might need to change
# Location of spamdyke configuration file
sdconf=/etc/spamdyke/spamdyke.conf
#########################################################################
# check/obtain parameter values
#########################################################################
a2_check_parameters(){
if [ ! -f "$sdconf" ]; then
echo "$me - config file \"$sdconf\" does not exist"
exit 1
fi
gldir=$(q21_get_spamdyke_parm graylist-dir)
glmax=$(q21_get_spamdyke_parm graylist-max-secs)
if [ ! "$silent" ]; then
echo "$me processing graylist tree at $gldir ..."
echo "$me pruning entries older than $glmax seconds ..."
fi
}
#########################################################################
# get a spamdyke configuration parameter
#########################################################################
q21_get_spamdyke_parm(){
sdparm=$(grep "$1=" $sdconf)
echo "${sdparm#$1=}"
}
#########################################################################
# process each domain in the graylist tree
#########################################################################
a5_process_domain(){
domname=${dompath##*/}
if [ ! "$silent" ]; then
echo "$me processing domain $domname ..."
fi
domtot=$(q51_count_graylist_entries)
if [ ! "$silent" ]; then
echo "$me $domname - $domtot entries found"
fi
# delete files that are expired
domdlf=$(find $dompath -type f -mmin +$[$glmax/60] -exec rm {} \; -print | wc
-l)
# delete empty directories
domdld=$(find $dompath -depth -mindepth 2 -type d -empty -exec rmdir {} \;
-print | wc -l)
domrem=$(q51_count_graylist_entries)
if [ ! "$silent" ]; then
echo "$me $domname - $domdlf entries removed"
echo "$me $domname - $domdld empty directories removed"
echo "$me $domname - $domrem graylisting entries remain"
fi
graydom=$[$graydom+1]
graytot=$[$graytot+$domtot]
graydlf=$[$graydlf+$domdlf]
graydld=$[$graydld+$domdld]
grayrem=$[$grayrem+$domrem]
}
#########################################################################
# count the number of files (entries) in the graylist tree
#########################################################################
q51_count_graylist_entries(){
echo $(find $dompath -type f | wc -l)
}
#########################################################################
# main execution begins here
#########################################################################
me=${0##*/}
myver=v0.3.0
unset silent
if [ ! -z "$1" ]; then
case $1 in
-s )
silent=$1
;;
* )
echo "$me usage: $me [-s]"
exit 2
;;
esac
else
echo "$me $myver"
fi
a2_check_parameters
for dompath in $(find $gldir -mindepth 1 -maxdepth 1 -type d); do
a5_process_domain
done
if [ ! "$silent" ]; then
echo "$me total - $graydom domains processed"
echo "$me total - $graytot entries found"
echo "$me total - $graydlf entries removed"
echo "$me total - $graydld empty directories removed"
echo "$me total - $grayrem graylisting entries remain"
fi
exit 0
_______________________________________________
spamdyke-users mailing list
spamdyke-users@spamdyke.org
http://www.spamdyke.org/mailman/listinfo/spamdyke-users