LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   very basic inquiry (https://www.linuxquestions.org/questions/programming-9/very-basic-inquiry-105164/)

ixion 10-17-2003 11:05 AM

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?

Hko 10-17-2003 11:53 AM

I use this in my firewall script to do the same:
Code:

ifconfig eth0 | sed -n 's/.*inet *addr:\([0-9\.]*\).*/\1/p'


All times are GMT -5. The time now is 08:51 AM.