LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2014, 02:55 AM   #1
AndrewNZ
LQ Newbie
 
Registered: Nov 2013
Posts: 16

Rep: Reputation: Disabled
Query large amount of domains


Hi ,

I have a list of domains in a spreadsheet and I want to find out the MX records for all of them. How can I write something in bash to check this?

Thank you.
 
Old 08-21-2014, 03:33 AM   #2
jessetaylor84
Member
 
Registered: Jan 2014
Location: Olympia, WA
Distribution: Debian / Tails
Posts: 47

Rep: Reputation: 10
To look up the MX record, you can use:

Code:
nslookup -query=mx www.example.com
You will somehow need to create a list of domains from the spreadsheet (how you do so depends on the spreadsheet format). Then you can loop through each of the domains in the list and look it up with nslookup.

If you need guidance on how to use loops in bash, check out this guide.
 
Old 08-21-2014, 03:36 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353
Code:
dig +short @8.8.8.8 optusnet.com.au MX
returns
Quote:
50 extmail.optusnet.com.au.
so wrapping the command in a loop
Code:
while read aline; do
  ...
done < domains.txt
should be getting close to what you want.
 
Old 08-21-2014, 04:01 AM   #4
AndrewNZ
LQ Newbie
 
Registered: Nov 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
so where its ... put dig something?
 
Old 08-21-2014, 04:09 AM   #5
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353
Yes
Code:
  echo $aline # Echo the line read from domains.txt
  dig +short @8.8.8.8 $aline MX # Do the MX record lookup
 
Old 08-21-2014, 06:38 PM   #6
AndrewNZ
LQ Newbie
 
Registered: Nov 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
When I write the following I just get ">" on a line after?

while read aline; do dig +short $aline mx done < domains.csv
 
Old 08-21-2014, 08:17 PM   #7
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353
At the command line you need an additional semicolon to separate the statements.
Code:
while read aline; do dig +short $aline MX; done < domains.csv
The type of record to query needs to specified as MX. Note the capitalisation.

Hopefully your domains.csv file contains the domains listed one per line and you have run the file through a utility such as fromdos to convert the CRLF line endings to LF only line endings.

Last edited by allend; 08-21-2014 at 10:33 PM. Reason: Additional comment on MX
 
Old 02-08-2015, 03:18 PM   #8
chris2k
LQ Newbie
 
Registered: Aug 2013
Posts: 2

Rep: Reputation: Disabled
i would use the for command like descriped here:

Code:
for i in `cat domain.csv`; 
do 
echo $i
dig $i mx +short 
done
I would echo the domain too, because for example google has more mx-records for one domain.

Or if you want to have a semicolon-seperated output:

Code:
IFS='
'
for i in `cat domain.csv`
do
 for j in `dig $i mx +short`
 do
  echo $i";"`echo $j | sed -e "s/^[0-9]* //g"`
 done
done
for example, in your domain.csv is yahoo.com and google.com - this is the output:

Quote:
google.com;alt1.aspmx.l.google.com.
google.com;alt4.aspmx.l.google.com.
google.com;alt2.aspmx.l.google.com.
google.com;alt3.aspmx.l.google.com.
google.com;aspmx.l.google.com.
yahoo.com;mta6.am0.yahoodns.net.
yahoo.com;mta7.am0.yahoodns.net.
yahoo.com;mta5.am0.yahoodns.net.

Last edited by chris2k; 02-08-2015 at 03:49 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Moving large amount of data to another drive Quads Linux - Newbie 6 03-04-2014 03:59 PM
Archiving large amount of mails ddaas Linux - Server 2 07-18-2013 02:37 AM
renaming a large amount of files kaplan71 Linux - General 5 09-20-2011 09:08 PM
HP laserjet 6p stalls with large amount of data simjii Mandriva 0 11-10-2005 04:32 PM
A large amount of problems DaBlade Linux - General 4 12-04-2004 06:47 AM


All times are GMT -5. The time now is 12:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration