awk nslookup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk nslookup
# 1  
Old 02-21-2016
awk nslookup

Hi,

I have a rather simple awk statement to perform an nslookup on a file (list of IPs). If the lookup yields a result, then it sends it to a file. If no result, there is no output. I've been trying to use !NR or !NF with an if statement to make the output state "NA" if there is no result, but have not been successful. This may be a simple question, but any guidance would be much appreciated.

Code:
awk '{print $3}' $dir/$tag.out1 | nslookup | grep Name | awk '{print $2}' > lookup.out

looking to get output:
Code:
xyz.com
abc.com
NA
rty.edu
NA


Last edited by Scrutinizer; 02-21-2016 at 02:53 AM.. Reason: code tags
# 2  
Old 02-21-2016
Perhaps this awk will fill your requiremnt :
Code:
awk ' { print (system("nslookup " FS $0 FS "2>&1 > /dev/null")) ? "NA" : $0 } ' file > newfile

# 3  
Old 02-21-2016
How about (untested)
Code:
... | awk '{L = 1; print $2} END {if (!L) print "NA"}' > lookup.out

# 4  
Old 02-21-2016
My input is like so:
A B 1.1.1.1 C 2.2.2.2 D E F

This yielded an undesired output.
awk ' { print (system("nslookup " FS $0 FS "2>&1 > /dev/null")) ? "NA" : $0 } ' file > newfile

Cannot lookup A
NA

I'm looking to resolve the two IPS and send to file. If they are not resolvable, then output NA for the respective output.
# 5  
Old 02-21-2016
This highly depends on your nslookup's output. With mine, this works:
Code:
awk '{print $3; print $5}' file | nslookup | awk '/[Nn]ame/ {print $NF} /can.t/ {print "NA"}'

This User Gave Thanks to RudiC For This Post:
# 6  
Old 02-21-2016
it's not picking up the "can't", since standard error is being displayed, as opposed to being piped to the last awk statement. so the NA isn't being printed when

fyi, I'm running this through cygwin emulator. The script will then either be hosted on a linux server or another cygwin.

** server can't find 1.1.1.1.in-addr.arpa: NXDOMAIN

---------- Post updated at 04:26 PM ---------- Previous update was at 04:14 PM ----------

never mind, I just redirected both stnd out and stderr
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

nslookup hanging

Hey folks. Long time lurker, first time poster. I'm a bit of a newbie at "coding" (obviously, scripting is a teensy bit different than coding) and I've run into a problem that I just can't seem to get around. I'm going through a list of servers to check their name, IP, reverse-NSLOOKUP name and... (2 Replies)
Discussion started by: Bearwhale
2 Replies

2. Solaris

nslookup command

hi, I am new in Solaris 10 , i am installing a software in solaris 10, while performing pre requisite nslookup command should return without error, and the IP address and host should match those listed in the etc/hosts file, but nslookup command show the below error , can anybody tell me how i... (4 Replies)
Discussion started by: zeeshan047
4 Replies

3. Emergency UNIX and Linux Support

Nslookup!!! Please look up!!!

Hi all Nslookup command returns!!!! Code: nslookup 10.91.44.29 Server: 127.0.0.1 Address: 127.0.0.1#53 29.44.91.in-addr.arpa name = station1.example.com Code: nslookup station1.example.com Server: 127.0.0.1 Address: 127.0.0.1#53 Name: ... (4 Replies)
Discussion started by: anishkumarv
4 Replies

4. Shell Programming and Scripting

nslookup: am I doing it right?

Hi guys, I'm back to get some help again :) I have a file that has a list of IP addresses, and I use nslookup in my script to resolve hostnames of those IPs. the problem I'm facing is that I not all the hostnames got resolved! and I don't know why. sometimes the same duplicate IP returns a... (8 Replies)
Discussion started by: Abdulelah
8 Replies

5. UNIX for Advanced & Expert Users

nslookup for Unix

I am connecting from windows via Putty to some other Unix server. How can I display my current windows MachineName/NTID in putty? Thanks :) (4 Replies)
Discussion started by: som.nitk
4 Replies

6. IP Networking

nslookup strangness

hi, what would cause the nslookup to work one way but not the other? for most machine it works both ways. >nslookup 172.18.10.235 Server: 172.16.17.3 Address: 172.16.17.3#53 235.10.18.172.in-addr.arpa name = machine1.prod.local >nslookup machine1 Server: ... (3 Replies)
Discussion started by: purest
3 Replies

7. UNIX for Advanced & Expert Users

nslookup problem

I am having trouble configuring BIND 8.3 on Solaris 9. When I run nslookup, I get this error/message: test# nslookup *** Can't find server name for address 192.168.1.31: Non-existent host/domain *** Default servers are not available I double checked everything and I can't figure this out. I... (8 Replies)
Discussion started by: xnightcrawl
8 Replies

8. Shell Programming and Scripting

NSLOOKUP script

Hi Anyone know of a quick and simple way to script an NSLOOKUP's from a list/text file? Thanks, Gav (1 Reply)
Discussion started by: gavcollins
1 Replies

9. UNIX for Dummies Questions & Answers

nslookup on linux ???

Hi I usually use solaris but Im working right now with a Linux box and I cannot find the nslookup command. Does Linux use this command or have an other one to do dns querys?? Thanks and sorry for such a dumb question.. :) (2 Replies)
Discussion started by: piltrafa
2 Replies

10. UNIX for Advanced & Expert Users

named and nslookup

Guys , Am using Linux - Red Hat 6.1 . My DNS and nslookup command was working fine and ppl. can resolve through this server . but i changed something in /etc/named.conf , that stopped the DNS . The named proccess is working , but nslookup command is not , i get this error message : ... (3 Replies)
Discussion started by: tamemi
3 Replies
Login or Register to Ask a Question