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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-07-2007, 05:06 PM
|
#1
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Rep:
|
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
|
|
|
11-07-2007, 08:10 PM
|
#2
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,426
|
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
|
|
|
11-08-2007, 04:36 AM
|
#3
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
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 04:38 AM.
|
|
|
11-08-2007, 05:03 AM
|
#4
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
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
|
|
|
11-08-2007, 05:51 AM
|
#5
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
thanks it works perfect,
grep -lR 'foo' /blah/foobar | xargs grep -lR 'blah'
cheers!!!
|
|
|
All times are GMT -5. The time now is 01:31 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|