LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-21-2004, 04:09 AM   #1
PcHammer
Member
 
Registered: Jan 2001
Location: Ljubljana Slovenija
Distribution: Slackware
Posts: 70

Rep: Reputation: 15
Bash programing using 2 variables


I would need some help with my bash programing.
I have this line in my rc.firewall:
iptables -t nat -I PREROUTING -i eth0 -s $ip -m mac --mac-source ! $mac -j DROP

$ip and $mac are variables that are in a separate file (coma delimited)
Now I would like to use this file to load them into this iptables rule, and that pipe tham into another file.

If anyone know how to do this pls help.


Regards, PcHammer
 
Old 04-21-2004, 08:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Not elegant, but it should give you an idea:

Code:
#!/bin/sh

sed 's/,/ /' /ip-mac-inputfile | \
while read IP MAC
do
  echo "ip=$IP - mac=$MAC"
  echo "iptables -t nat -I PREROUTING -i eth0 -s $IP -m mac --mac-source ! $MAC -j DROP"
done
This reads the entries form your ip-mac-inputfile and (after removing the echo an the double quotes) will set up a rule for all entries in this inputfile.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash programing Paxmaster Programming 1 08-23-2005 06:09 PM
bash variables pfaendtner Linux - Newbie 4 11-23-2004 01:00 PM
Bash programing problem zWaR Programming 3 01-01-2004 05:57 PM
Variables in bash tcaptain Programming 1 03-03-2003 02:07 PM
Bash variables pk21 Programming 2 01-09-2003 03:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:28 PM.

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