#!/bin/bash SPAMMER_REGEX="www\.\(razordude\|jmhic\|whvc\)\.com" TMPFILE="/tmp/blacklist-ip.txt" LOGFILE="/var/log/apache/access.log" TEMPLATE="/home/atzm/template.htaccess.tdiary.txt" HTACCESS="/home/atzm/www/diary/.htaccess" function get_ip_list(){ # check and renew black-list IP addresses if [ -f "${TMPFILE}" ]; then PREV="`cat ${TMPFILE}`" fi RENEWED="${PREV} `cat ${LOGFILE} | grep ${SPAMMER_REGEX} | cut -d' ' -f1 | sort | uniq`" for ip in ${RENEWED}; do echo ${ip}; done | sort | uniq | tee ${TMPFILE} } BLACKLIST="`get_ip_list`" { cat ${TEMPLATE} echo "${BLACKLIST}" | sed -e "s/^/Deny from /" } > ${HTACCESS}