LinuxQuestions.org
Visit Jeremy's Blog.
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 10-17-2003, 11:05 AM   #1
ixion
Member
 
Registered: Dec 2002
Location: USA
Distribution: SuSE, CentOS, Gentoo
Posts: 166

Rep: Reputation: 30
very basic inquiry


I'm trying to extract information from my '/etc/resolv.conf' file for a firewall script. The interface will be assigned IP and DNS info via DHCP, and to keep things fairly strict, I want to have the IP and DNS info used in my firewall script. Here is what I've done so far (if someone has a better solution, please don't hesitate to correct me!):

Code:
ifconfig |grep eth0 -C 1|grep inet|cut -d ':' -f 2|cut -d ' ' -f 1 > IIP
cat /etc/resolv.conf | cut -d ' ' -f 2 > DNS
The first line returns my IP just fine. The second, however, creates 2 - 4 lines (whatever DNS entries have been assigned). How would I limit what lines I want? (ie, DNS1 = the first line, DNS2 = the second line, etc.).

The other thing is that this method saves the info to a file (due to the '>'). What if I just want a variable in the firewall script to be assigned the information?
 
Old 10-17-2003, 11:53 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I use this in my firewall script to do the same:
Code:
ifconfig eth0 | sed -n 's/.*inet *addr:\([0-9\.]*\).*/\1/p'
 
  


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
Squid inquiry ImAnEwBiE Linux - Newbie 1 10-26-2006 04:19 AM
SQUID inquiry depam Linux - Software 1 10-17-2005 02:15 AM
vsftp inquiry depam Linux - Software 3 10-12-2005 03:48 PM
Certification Inquiry Slacks98 Linux - Certification 1 11-23-2004 08:53 AM
fluxbox inquiry pathogenik Linux - General 12 07-14-2002 06:34 AM

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

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