Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

script to run dig using a file input

Posted on 2011-02-20
7
1,026 Views
Last Modified: 2012-05-11
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



0
Comment
Question by:richsark
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Fairlight2cx
ID: 34940939
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.)
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34941129
How about

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

wmp
0
 
LVL 1

Author Comment

by:richsark
ID: 34942934
Hello woolmilkporc:

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

egrep  -i '([^\.]wan|^wan)test.txt'
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:richsark
ID: 34942944
Hello Fairlight2cx:,

Do you have this script that I can test on?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34942956
egrep  -i '([^\.]wan|^wan)test.txt' output.txt
0
 
LVL 1

Author Comment

by:richsark
ID: 34943192
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?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 34943268
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.  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question