jamesjwilsonsr
December 22nd, 2011, 06:10 AM
I'm primarily a "Windows" systems administrator whose been getting his toes in the Linux waters. I am new to programming and advanced scripting so please bear with me and my incomplete example below.
I have exported all entries from our DNS zones. I used sed to remove everything other than the fqdn from the files. We have a few hundred hosts across a few dozen zones. Some hosts are not in all zones though.
I would like to use something like awk to determine which hosts are (or are not) in the domains I specify. Bonus might also be to accept input from a file (with the various domain names) but the simpler the better.
the file looks something like this:
host1.domain1.com
host1.domain2.com
host1.domain3.com
host1.domain4.com
host2.domain1.com
host2.domain2.com
host2.domain3.com
host2.domain4.com
and so on. And again, some hosts are not in all zones.
I would like to do something like:
awk -F"." '($2 == "domain2" && $2 == "domain3") {print $1}' filename
to figure out which hosts are (or maybe, are not) in the zones specified.
Obviously this script is incomplete. I can't figure out how to find duplicates from $1 and then search $2 for domain2 and domain3.
I want all hosts from $1 that match a few possible domain inputs from $2 to return, and nothing else. Since I may have the same host returned per domain a few times, if the result could be truncated to just the host once, even better.
I am not necessarily looking to be spoon fed a few completed examples. If you have a few ideas for me, I'd appreciate being pointed closer in the right direction.
I have exported all entries from our DNS zones. I used sed to remove everything other than the fqdn from the files. We have a few hundred hosts across a few dozen zones. Some hosts are not in all zones though.
I would like to use something like awk to determine which hosts are (or are not) in the domains I specify. Bonus might also be to accept input from a file (with the various domain names) but the simpler the better.
the file looks something like this:
host1.domain1.com
host1.domain2.com
host1.domain3.com
host1.domain4.com
host2.domain1.com
host2.domain2.com
host2.domain3.com
host2.domain4.com
and so on. And again, some hosts are not in all zones.
I would like to do something like:
awk -F"." '($2 == "domain2" && $2 == "domain3") {print $1}' filename
to figure out which hosts are (or maybe, are not) in the zones specified.
Obviously this script is incomplete. I can't figure out how to find duplicates from $1 and then search $2 for domain2 and domain3.
I want all hosts from $1 that match a few possible domain inputs from $2 to return, and nothing else. Since I may have the same host returned per domain a few times, if the result could be truncated to just the host once, even better.
I am not necessarily looking to be spoon fed a few completed examples. If you have a few ideas for me, I'd appreciate being pointed closer in the right direction.