LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-28-2004, 04:24 AM   #1
eiem
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
Reading data from file (field organizzation)


hi folk,
I'm a
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
 
Old 03-29-2004, 05:03 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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
 
  


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
Reading audio data files as an actual audio file? Erik_the_Red Linux - Software 1 06-01-2005 07:22 AM
What is the data type field definition to save RTF file? Linux4BC Linux - General 3 06-02-2004 04:19 AM
Reading comma-separated data from file MeLassen Programming 4 04-04-2004 02:41 PM
reading data from a file afrm Programming 2 12-16-2003 07:43 PM
Reading COM Port Data croakofonix Programming 1 06-11-2003 04:17 PM

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

All times are GMT -5. The time now is 10:42 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