Checking domain records of domains in cPanel – Bash script

We’ve got a project coming up that will require us to have a list of every A record and nameserver for domains hosted (or partially hosted) on our cPanel servers.

This is a bash script for listing out those details,  feel free to tinker and edit it to get the details or functionality you need.



for filename in /var/named/*.db; do
        f=$(basename "$filename")
        ipaddress=`dig $domain +short`
        nameserver=`whois $domain | grep "Name Server" | cut -d ":" -f 2 |
sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'`

        echo -e  "$domain = $ipaddress, $nameserver"

Leave a Reply

Your email address will not be published. Required fields are marked *