Issue
Hello I am trying to pull the ns records for a few domains we own. I want to script it so the data is formatted in domain name, ns record, ns record, ns record domain name, ns record, ns record, ns record domain name, ns record, ns record, ns record
What I am getting is
domain name, ns record, ns record, ns record ns record, domain name, ns record, ns record ns record, ns record, domain name, ns record
here is the command I have got so far but it organises in alphabetic order.
Input
cat dom.txt
domain1.com
domain2.com
domain3.com
awk '{print}' < dom.txt | while read domain; do nslookup -type=ns $domain | grep nameserver | sed -e 's/nameserver =//g' -e 's/.$//' | awk '{print $1 "\n" $2}' | sort -u | tr '\n' ',' | sed -e 's/,$//' | awk '{print}'; done
Solution
On way, using dig
and shell: tested mostly bourne
* bash
, dash
, ash
, yash
, ksh
, zsh
, sh
(but not csh
& fish
compliant):
$ cat dom.txt
example.org
w3c.org
gnu.org
$ while read domain; do
echo "$domain,$(dig +short NS "$domain" | paste -sd ',')"
done < dom.txt
Output
example.org,a.iana-servers.net.,b.iana-servers.net.
w3c.org,ns-139-c.gandi.net.,ns-225-a.gandi.net.,ns-206-b.gandi.net.
gnu.org,ns3.gnu.org.,ns2.gnu.org.,ns1.gnu.org.
Answered By - Gilles Quénot Answer Checked By - Timothy Miller (WPSolving Admin)