#!/usr/bin/env bash # # Expire old RBL records listtype=$1 if ! [[ "$listtype" =~ ^[4,6]+$ ]]; then echo "first parameter is mandatory and must be either 4 or 6." exit 1 fi rblfile="/var/lib/rbldns/listv$listtype" 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 fi done fi # FIXME: ipv6 regex needed if [ $listtype -eq 6 ]; then : fi # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4