LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 11-07-2007, 04:06 PM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Find the config file of a network interface


Hello,
I'm trying to find out two things here, if there is an easy way to find out the network configuration file that the network interface has been assigned to eg:

1. My linux machine has ifcfg-eth0 but if you had more interfaces this file might be ifcfg-eth1, or ifcfg-foobar.
Anyway the point is the IP address could be on any type of network interface therefore i can't hard code into my script which file the ip address is configured in because it will change depending on the interface being used for the connection, and as this is a script i want it to be able to find out itself. Is there a way to do this??

2. One idea i came up with is to search all the network interface config files and then get it to return the file with the ip address settings in it, i could do this with grep but wonder how you can get grep if possible to search for more than one argument at a time i.e

grep -R if '192' && '255' && '543'

so i'm saying if a file contains '192' '255 '543' anywhere in its contents then as grep does, print out the path to that file. I just dont know if its possible to get grep to search many strings in a file all at the same time??

So if there is an answer to number 1. i'm very interested, but as a compromise and answer as to if grep with several strings for arguments is possible would be great and probably do the job to?

Thanks and Regards
 
Old 11-07-2007, 07:10 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
something along these lines ?

Code:
cd <dir with ifcfg files>
for file in `ifcfg-*`
do
    grep $ip $file >/dev/null 2>&1
    if[[ $? -eq 0 ]]
    then
        echo "file is $file"
    fi
done
 
Old 11-08-2007, 03:36 AM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Yeah like that, but i basically just want to know if you can get grep to match more than one text string within a file, but i dont know if it is able to match more than one set of strings in a file.
So if file contains 'the' and 'help' and 'blah' and 'foobar' then that is the correct file and print the file's path to stdout including the file name.

Cheers

ps- to be honest i doubt you'd need the for look as grep can look in all the files and print output of which file anyway, so all i really need is to know if you can grep for several things at once and how?

Last edited by helptonewbie; 11-08-2007 at 03:38 AM.
 
Old 11-08-2007, 04:03 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
well, if you play with your network settings it's usually done in the
rc.local file

as for searching for multiple strings,
easiest is,

grep -l THIS *.file | xargs grep -l THAT | xargs grep -l THE_OTHER

Code:
files with stdio.h
billym.>grep -l  stdio.h *|cat -n                
     1  dtb_utils.c
     2  robots.c
     3  robots_stubs.c

files with stdio.h and sprintf
billym.primadtpdev>grep -l  stdio.h *| xargs grep -l sprintf | cat -n
     1  dtb_utils.c
     2  robots_stubs.c
 
Old 11-08-2007, 04:51 AM   #5
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
thanks it works perfect,

grep -lR 'foo' /blah/foobar | xargs grep -lR 'blah'

cheers!!!
 
  


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
Network Interface Card config problem dcalki Linux - Hardware 2 11-01-2007 02:14 PM
unable to find network interface (ipw3945) walter81 Linux - Wireless Networking 3 09-28-2007 05:41 PM
Urgent : How to find whether the Network Interface is DHCP enabled or not ? abha_shrimal Linux - Networking 3 12-15-2005 01:50 PM
WINE - CONFIG File, can't find it to do first config Hero Doug Linux - Software 1 09-06-2005 11:03 AM
Network Interface Config at Bootup lyew Linux - Networking 1 05-03-2003 08:57 PM


All times are GMT -5. The time now is 01:25 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration