script to run dig using a file input

richsark
richsark used Ask the Experts™
on
Hello,

I am using dig -f ( -f means a file name) which I have a list if zones. like
test.com
hello.com
foo.com
foobar.com
help.us

It runs fine but I only want to know if a certain NS record exists. For example wan.rich.com if that criteria matches create a file with the domain name and NS record.

If wan.rich.com is not part of the NS record then output a file with the zone name and the NS record

example

Zone name:                        NS Record                      
test.com                             wan.rich.com
foo.com                              att.ttl.com

Report 2

All zones that have wan.rich.com are:

foo.com
apple1.com
box.com

is there a grep or sed command to go through the file to show me?

I tried grep -i wan.rich.com output.txt

I get a response 3 times for each zone meaning duplicates cause there are wan.rich.com,  1.wan.rich.com, 2.wan.rich.com and 3.wan.rich.com for each zone name

Each domain has these 3 entries, I just want to know per domain. I dont want to end up with a report that has 3 same domains for each NS record.

Thanks



Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'd do it in perl and every time I found an NS record that matched the selection criterion, I'd store the results in an array.  Then just spit out the array for the report section.

If the report had to handle multiple criterion, I'd use a hash with each match criterion as the key for the hash, and push onto an array the values for those keys.  (Hash of arrays.)
Most Valuable Expert 2013
Top Expert 2013

Commented:
How about

egrep  -i '([^\.]wan|^wan).rich.com'

wmp

Author

Commented:
Hello woolmilkporc:

Its not working. I am not sure how to run it.

egrep  -i '([^\.]wan|^wan)test.txt'
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
Hello Fairlight2cx:,

Do you have this script that I can test on?
Most Valuable Expert 2013
Top Expert 2013

Commented:
egrep  -i '([^\.]wan|^wan)test.txt' output.txt

Author

Commented:
Hi woolmilkporc:

Well, I must be a dunce, i did egrep  -i '([^\.]wan|^wan)test.txt' output.txt

may I know what is test.txt?
output.txt contains the data I want to grep on right?
Most Valuable Expert 2013
Top Expert 2013
Commented:
OK,

I inadvertently copied the line from your comment and overlooked your test.txt. You put it there, so I don't know what it is.

egrep  -i '([^\.]wan|^wan).rich.com' output.txt

Yes, "output.txt contains the data I want to grep on".

The statement does nothing else than grepping for "wan.rich.com" without the dot "." in front, so "1.wan.rich.com" or the like will not be found.
The string following the pipe "|" takes care to find "wan.rich.com" at the start of a line as well.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial