LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-21-2010, 09:54 AM   #1
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Rep: Reputation: 16
Question NSLOOKUP - One Line cmd Line


Hi all,

I am trying to use "NSLOOKUP" to get hostname of my linux servers. when i do NSLOOKUP BY IP address i get the following:
Code:
NSLOOKUP 199.203.63.32
......blah blah blah .........................
......blah blah blah .........................
......blah blah blah .........................

32.63.203.199-IP-in-addr.arpa name = NS-exchangeserver-main.local.south-east.com

32.63.203.199-IP-in-addr.arpa name = NS-exchangeserver.local.south-east.com

32.63.203.199-IP-in-addr.arpa name = timezone1.local.south-east.com
what i am interested in is to get NS-exchangeserver-main whenever i do a NSLOOKUP for any servers with IP address.

but that entry not always is the first line it could appear on the 2nd or 3rd line. but what is always there is the 2nd "-" like in:
Code:
NS-exchangeserver-main
so far tried different ways but not able to get it right,.. tried like:

nslookup 199.203.63.32 | grep -ir "name" | awk -F "-" "{print $2}"

also use cut command but not able to get only:
NS-exchangeserver-main

any help would be appreciated.

Thanks.
 
Old 09-21-2010, 10:23 AM   #2
jangovich
LQ Newbie
 
Registered: Sep 2010
Location: Mississauga, Ontario
Distribution: Ubuntu 10.04
Posts: 21

Rep: Reputation: 5
How about this:

Code:
nslookup 199.203.63.32 | awk '{ print $4; }' | grep -ir "\w*-\w*-\w*\."
You can simplify grep expression of course
 
1 members found this post helpful.
Old 09-21-2010, 10:28 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,772

Rep: Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054
Its late and I must have missed something. To clarify, I hope, you want to check if your nslookup of a particular ip contains the line 'NS-exchangeserver-main' some where?
What has 'name' got to do with anything?

Your awk is probably returning 'IP' as it is the second field in your example above.

Do you actually want to return that text or just acknowledge that it is there?
 
Old 09-21-2010, 10:29 AM   #4
WoodsyDotOrg
LQ Newbie
 
Registered: Sep 2010
Posts: 8

Rep: Reputation: 1
Not entirely sure what part of the data you are attempting to retrieve.

Are you saying, it could be on any line, but it always has two dashes?

If so, here's something...

Code:
nslookup <ip>|egrep '='|cut -d"=" -f2-|cut -d"." -f1|egrep '^[ a-zA-Z0-9]+-[a-zA-Z0-9]+-'|sed 's/^[ ]*//'
Hope that helps.

Last edited by WoodsyDotOrg; 09-21-2010 at 10:33 AM.
 
Old 09-21-2010, 10:49 AM   #5
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Hi all, thanks for your quick reply.
this is nice to have you guys around, once again BIG THANKS.

i got my answer by adding to the 1st reply (from jangovich)>>> | cut -s -d"." -f1

i need to get the "name" server to check my DNS values are ok. so when I do NSLOOKUP it starts with name: and the values of my DNS server(answer to my frind grail - hope it is clear)

Also, WoodsyDotOrg thanks for your pots i will try your code.

Have a NICE day!!!
 
Old 09-21-2010, 07:36 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,772

Rep: Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054
Well assuming I am on the right page now I see no need for so many extra commands:
Code:
nslookup <ip> | awk 'tolower($2) == "name"{print gensub(/\..*/,"","g",$4)}'
 
1 members found this post helpful.
Old 09-23-2010, 07:53 AM   #7
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Thanks grail for given a simpler code.
i tried & works great.

Have a Nice day.
 
  


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
[SOLVED] Cmd Line help SteveThePirate Linux - Newbie 7 08-14-2009 02:40 AM
Cmd line bittorrent quesiton Jukas Linux - Software 2 10-27-2005 03:55 PM
cmd line send attachment? jedimastermopar Linux - General 2 06-16-2005 12:51 PM
Best distro for cmd-line webserver Seft Linux - Newbie 4 11-15-2003 03:32 AM
booting then to cmd line..... Why not to GUI?? Ax787 Linux - Newbie 1 10-28-2003 10:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration