various fixed to RBL scripts

This commit is contained in:
Oliver Ladner 2018-10-09 13:37:19 +02:00
commit ef64b181cc
3 changed files with 24 additions and 29 deletions

View file

@ -4,21 +4,20 @@
listtype=$1
if ! [[ "$listtype" =~ ^[4,6]+$ ]]; then
echo "first parameter is mandatory and must be either 4 or 6."
exit 1
echo "first parameter is mandatory and must be either 4 or 6."
exit 1
fi
rblfile="/var/lib/rbldns/listv$listtype"
maxage=96 # in hours
maxage=168 # in hours
if [ $listtype -eq 4 ]; then
egrep '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}' $rblfile | while read -r ip delimiter timestamp foo; do
if [ "$timestamp" -gt "0" ]; then
expiration=$(echo "$(date +%s)-$timestamp" | bc)
if [ "$expiration" -gt "$(($maxage * 3600))" ]; then
#echo "DEBUG: entry $ip older than $maxage hours (expired $(($expiration / 3600)) hours ago)"
sed -i "/^$ip.*# $timestamp.*$/d" $rblfile || echo "Error while deleting $ip: $?"
fi
if [ "$timestamp" -gt "0" ]; then
expiration=$(echo "$(date +%s)-$timestamp" | bc)
if [ "$expiration" -gt "$(($maxage * 3600))" ]; then
#echo "DEBUG: entry $ip older than $maxage hours (expired $(($expiration / 3600)) hours ago)"
sed -i "/^$ip.*# $timestamp.*$/d" $rblfile || echo "Error while deleting $ip: $?"
fi
fi
done
fi
@ -27,3 +26,5 @@ fi
if [ $listtype -eq 6 ]; then
:
fi
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4