I have a file that has a list of "bad" IP addresses. I want to import this file of bad IP addresses into my .htaccess file to deny access via apache.

I want to automate this process using sed. How would I go about doing this?

link|improve this question

61% accept rate
Nothing (ok, nothing much) to do with sys administration. – Ward May 31 '11 at 4:46
I have a file that contains some bad ip address , and i want to automate the process to add those ip to .htaccess for denying. Is it not a part of system administration ? – vnix27 May 31 '11 at 5:21
your question doesn't actually mention that - we're not mind readers. Anyhow, whilst that might be the exact usage scenario, the question itself is about using sed. – Mark Henderson May 31 '11 at 5:43
I have updated your question for you, as now it's about a thousand times more relevant and is a lot easier for people to answer. – Mark Henderson May 31 '11 at 5:46
Thanks a lot for making question relevent , i will take care from next time – vnix27 May 31 '11 at 6:52
feedback

2 Answers

up vote 0 down vote accepted

You can make .htaccess template with "%BANNED_IP_LIST%" in place where that list should be and use something like sed -e "s/%BANNED_IP_LIST%/$(cat banned.txt)/" to create actual .htaccess file.

link|improve this answer
I never used .htaccess template, let me try – vnix27 May 31 '11 at 7:10
feedback

Why sed? Use fail2ban. It can be configured to work with many different services, including Apache.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.