LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2009, 10:14 AM   #1
Yalla-One
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Slackware, CentOS
Posts: 641

Rep: Reputation: 36
read ip addresses from file in shell script


Hi,

I have a text file of IP addresses, one IP address on each line, that i would like to ban in iptables.

Can anyone kindly advise of a simple, but robust, script to read a text file line by line and put its contents in a variable so that I can do a drop on each offender:
Code:
iptables -A INPUT -s $IP_ADDRESS_FROM_FILE -j DROP
Thanks in advance!
 
Old 11-08-2009, 10:19 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
The standard loop for this:
Code:
while read lin; do
    echo $lin
done < filename
Instead of "echo $lin", put in your desired code.
 
Old 11-08-2009, 10:22 AM   #3
Yalla-One
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Slackware, CentOS
Posts: 641

Original Poster
Rep: Reputation: 36
Thanks! So it was that simple, eh? I incorrectly assumed that had to be a shortcut or maybe insecure since it was so short... silly me :-)
Thanks much!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script read line from file, use it in command DiGiGoth Programming 5 08-31-2008 11:08 AM
[Shell] Read a File from script yussef Programming 4 08-19-2008 04:26 AM
shell script to read input from csv ip addresses? kr0m3 Programming 3 07-21-2007 08:51 AM
How to read data from file to use in shell script? ozymandias Linux - Newbie 7 10-27-2006 01:19 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration