LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Reading data from file (field organizzation) (http://www.linuxquestions.org/questions/programming-9/reading-data-from-file-field-organizzation-163297/)

eiem 03-28-2004 04:24 AM

Reading data from file (field organizzation)
 
hi folk,
I'm a :newbie:
first of all , excuse me for my english, it's not my natural language :P

than, we go stright on my problem:

for my firewall I want to make some configuration files like:

prerouting.conf
postrouting.conf
allow_forwarding.conf
allow_incoming.conf

4 example prerouting.cong:

"
#IP_machine PORT

#my pc
192.168.8.101 6000
192.168.8.102 12000

#production 2
192.168.5.103 21000
192.168.8.110 11023
"

And than, I want my rc.firewall like this:

"
#!/bin/bash
$iptables=/usr/sbin/iptables
$ANY="0.0.0.0\0"

.........(omissis)

#=============#
# Prerouting service #
#=============#

FILECONF="/etc/firewall/prerouting.conf"


cat $FILECONF | awk '!/#/&&/\y/ {

`$iptables -t nat -A PREROUTING -p tcp --dport $2 -i ppp0 -j DNAT --to $1:$2`

}'
"

I use "!/#/&&/\y/" to delete the "#" line and blank line
the ` command ` isn't accept from awk construct :(


I can use :

awk '......{

system(command)

}

but so I can't use variables in "command" neither internal variables (awk var) nor external (x ex.: $ANY or $iptables)...

So, I try to use the "for" loop like this

"
for HOST in "192.168.8.101 6000" "192.168.8.102 12000"
do
set -- $HOST
$iptables -t nat -A PREROUTING -p tcp --dport $2 -i ppp0 -j DNAT --to $1:$2
#during first loop, $1=192.168.8.101 and $2=6000 and so on...
done
"

It work fine good, but I don't know how to make,reading from file, an array made like this:

each field of array is made of a list of 2( or n..) elements: "IP PORT"

$HOSTLIST=("192.168.8.101 6000" ....

It dosen't work!


........

At the end of all, I don't know how to solve my problem: read 2 field data from a conf file!!!!
Anyone have some suggestions??!?!?!?!?

TNX... (even only for attantion!!! :P)

Alex, IT

bigearsbilly 03-29-2004 05:03 AM

i not sure i understand, but
if data file is:

Code:

address port
if you read into multiple variables it will split the line
into them for you, like "read a b c d e"
then do something like:

Code:

cat file | while read address port;do
  echo address=$address
  echo port=$port
done



All times are GMT -5. The time now is 12:27 PM.