Dig multiple cpanel domains

If you find yourself with a customer requesting to know where all the domains associated with a cpanel account are pointing to or are migrating accounts, you can do the following:

#for each in `ls /var/cpanel/users/*`; do grep DNS $each >> domains.txt; done;
#sed -i 's:.*DNS.*\=::gi' domains.txt ;
#for each in `cat domains.txt`; do echo "doing a dig on $each"; dig $each | grep -E "^$each.*\b(A|CNAME).*\..*\..*" ; echo ""; done;

The output will be something similar to;

doing a dig on cavemantech.net
cavemantech.net. 13970 IN A

doing a dig on cave.cavemantech.net
cave.cavemantech.net. 13970 IN A

doing a dig on training.cavemantech.net
training.cavemantech.net. 13970 IN A

doing a dig on wordpress.cavemantech.net
wordpress.cavemantech.net. 13970 IN A

doing a dig on roundcube.cavemantech.net
roundcube.cavemantech.net. 13970 IN A

doing a dig on confluence.cavemantech.net

doing a dig on dino.cavemantech.net
dino.cavemantech.net. 13970 IN A

Also if you need multiple queries for a specific record:
#dig example.com ns another.com ns

or if all records are needed:

#dig example.com any another.com any
which returns non-label (resource records) RRs for both domains

# dig example.com another.com any
which returns A (resource records) RR for 1st and non-label (resource records) RRs for 2nd domain

# dig example.com any another.com
which returns non-label (resource records) RRs for 1st and A (resource records) RR for 2nd


I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....