ProgrammingThis 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.
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.
what i am looking for is to get mainserver-local that is my matching pattern. But sometimes it is the first, second or third entery on the same line. any idea how to get mainserver-local regardless of position on the same line.
Yes i do have multiple DNS recs and by taking the right name i could del. the other ones. that's my next step. but i do not know how to get the right DNS rec. when they all come in one line separate by space in between them.
any idea? Thanks.
I am still in the learning phase around network stuff so please provide what the data would look like that awk is trying to examine?
Are you saying in your example above that the information you require may now not necessarily be the fourth ($4) field?
thanks for your reply grail. the code is just perfect. you did a good job. so f4 is good. the only thing is i have duplicated hostnames for that ip. That's why i get all the duplicated names. but i need only one. In my example, only "mainserver-local", and everytime i run the above code mainserver-local might comes first, second or third. so that's the issue to get the mainserver-local regardless in what position shows up. hope this could help. thank you again.
so the output of the above code is
- mainserver-local backupserver online-server
thank you for your reply ghostdog74.
your code outputs one of the hostnames every time it runs. but i need to output only the same hostname every time i run the code. so if i run it first time i get mainserver-local that's good but if i run it for the second time i get backupserver as first entry not mainserver-local.
ok .. I think I am with you. If I am I would guess that ghostdog's won't help much more either as the second lot of output with his would give backupserver which you do
not want .. is that correct?
Assuming yes, is there anything unique about the name of the server you are looking for? ie would it have the word local always in it?
Well I could be way off but this seems to boil back to my question from your previous post as to whether or not you need the name, which if unique I would think
you do not, or if you just need to test if it exists.
I would just use the following:
Code:
if nslookup <ip> | grep -q mainserver-local
then
<do stuff here>
fi
Ultimately if you did use the awk code then just change "name" to "mainserver-local", something like:
It works just fine. Big thanks!!
have question how can i use wildcards with the code. for example if there is something attached to the end of mainserver-local . Like mainserver-local1 or mainserver-local-sat23.
The // will find the text with or without any extra items so the * in there is not required.
What were you hoping to print? If you search and find mainserver-local you want to also have the variable filled with everything prior to period? (ie mainserver-local-sat23)
What were you hoping to print? If you search and find mainserver-local you want to also have the variable filled with everything prior to period? (ie mainserver-local-sat23)
yes grail, that is what i am looking for to get anything comes after mainserver-local-,
But right it does not do that it only prints mainserver-localand ignores -sat32 in mainserver-local-sat23)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.