Para evitar a execução de uma dig
e read
por linha do arquivo, você poderia fazer:
dig -f domains.txt mx +noall +answer
O que daria uma saída como:
stackexchange.com. 300 IN MX 5 alt1.aspmx.l.google.com.
stackexchange.com. 300 IN MX 1 aspmx.l.google.com.
stackexchange.com. 300 IN MX 10 alt3.aspmx.l.google.com.
stackexchange.com. 300 IN MX 10 alt4.aspmx.l.google.com.
stackexchange.com. 300 IN MX 5 alt2.aspmx.l.google.com.
google.com. 600 IN MX 10 aspmx.l.google.com.
google.com. 600 IN MX 30 alt2.aspmx.l.google.com.
google.com. 600 IN MX 20 alt1.aspmx.l.google.com.
google.com. 600 IN MX 40 alt3.aspmx.l.google.com.
google.com. 600 IN MX 50 alt4.aspmx.l.google.com.
Você pode canalizar para awk '{print $1,$5,$6}'
para remover o 300 IN MX .
Uma alternativa para o loop while read
poderia ser xargs:
$ xargs -tn1 dig mx +short < domains.txt
dig mx +short stackexchange.com
1 aspmx.l.google.com.
10 alt3.aspmx.l.google.com.
10 alt4.aspmx.l.google.com.
5 alt2.aspmx.l.google.com.
5 alt1.aspmx.l.google.com.
dig mx +short google.com
20 alt1.aspmx.l.google.com.
30 alt2.aspmx.l.google.com.
40 alt3.aspmx.l.google.com.
50 alt4.aspmx.l.google.com.
10 aspmx.l.google.com.