LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
Thread Tools
Old 11-08-2009, 11:14 AM   #1
Yalla-One
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Slackware
Posts: 599
Thanked: 8
read ip addresses from file in shell script


[Log in to get rid of this advertisement]
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!
linux Yalla-One is offline     Reply With Quote
Old 11-08-2009, 11:19 AM   #2
pixellany
Moderator
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch
Posts: 13,168
Thanked: 285
The standard loop for this:
Code:
while read lin; do
    echo $lin
done < filename
Instead of "echo $lin", put in your desired code.
linux pixellany is offline     Reply With Quote
Thanked by:
Old 11-08-2009, 11:22 AM   #3
Yalla-One
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Slackware
Posts: 599
Thanked: 8

Original Poster
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!
linux Yalla-One is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 12:08 PM
[Shell] Read a File from script yussef Programming 4 08-19-2008 05:26 AM
shell script to read input from csv ip addresses? kr0m3 Programming 3 07-21-2007 09:51 AM
How to read data from file to use in shell script? ozymandias Linux - Newbie 7 10-27-2006 02:19 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 09:23 PM


All times are GMT -5. The time now is 10:50 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration