Activities

October 2014
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Bash script : Identifying the external hosted domains from given domain list.

One of my client is planning to migrate his server to AWS which is having more than 283 websites hosted. So I given the active domain list and had to setup new name server using PowerDNS (Opensource DNS Manager) in order to suport AWS loadbalencer CNAME. Also I have created 283 Zone entries on this server to use this server as name server.

I’m facing a challenge which is , AWS loadbalencer does not give you an IP to use that loadbalencer as it may have changing time to time. So we need to put CNAME in place of primary DNS root record (@) which is not supported by most of the Name Registrars. Eg. Godaddy registrar will not support CNAME in place of domain root record.

PowerDNS is easy Name server and can be setup easily. We can manage this name server zone entry through poweradmin php application over the web from anywhere.

Here is the script which I used for list out the domain who is not manged by our name servers.

Input given

domain_list_file : a text file contains the lsit of all the domains hosted in the Cpanel server.
nameserver_check : This is the our current name serer name used for the hosting.

#!/bin/ksh
domain_list_file="/root/OR_Domain_names.txt"
ext_domain_file="/root/exterenal_domains.txt"
touch $ext_domain_file
nameserver_check="NS1.mydomain.com"
cat /dev/null > $ext_domain_file
counter=0
ext_count=0
while read line
do
clear
echo "Domain processed :: $counter, Active Domain:: $line , External Domains :: $ext_count "
name_server_name="$(whois $line | grep "Name Server" | awk '{print $3}'|head  -n 1)"

if [ "$name_server_name"  == "$nameserver_check"   ]
then
  echo " "
else
ext_count=$((ext_count+1))
#unset name_registrar_name
name_registrar_name="$(whois $line  | grep "Registrar" | awk '{print $2 $3}'|head  -n 1)"

echo "$line"  $name_registrar_name  >> $ext_domain_file
fi

counter=$((counter+1))

done <"$domain_list_file"

echo " ##### Done ####

my output will look like this,
Name_server_check

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>