Finding domain details with bash Here is my code to find the details of the domain. The domain can be feed as following:

bash script.sh domain1.com domain2.com
bash script.sh domains.txt &lt;-- not completed


The output should be in following format:

IP Address: 192.168.101.2
Server Name: servername.com
NS1: ns1.ournameserver.com
NS2: ns2.ournameserver.com
NS3: ns3.ournameserver.com
Datacenter: datacenter-name
Region: datacenter-13
Server Role: cPanel Web Server
Env: Production
Owner: xxxxxxxxxxx
Status: Active

IP Address: 192.168.101.2
Server Name: servername
NS1: ns1.ournameserver.com
NS2: ns2.ournameserver.com
NS3: ns3.ournameserver.com
Datacenter: datacenter-name
Region: datacenter-13
Server Role: cPanel Web Server
Env: Production
Owner: xxxxxxxxxxx
Status: Suspended


If it is in cloudflare:

Domain name: test.com
IP Address: 192.168.101.1
Server ID: N/A
Server Name: N/A
NS1: LYNDA.CLOUDFLARE.COM
NS2: DYN.CLOUDFLARE.COM
Datacenter: OVH
Region: HETZ-C3
Server Role: cPanel Web Server
Env: Production
Owner: xxxxxxxxxxx


Now it is only giving result in normal format, it also needs to be in JSON format

script.sh

#!bin/bash
HIP="$@"
check ()
{
    regexp="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
    nameserver=('@ns1.ournameserver.com' '@ns2.ournameserver.com' '@ns3.ournameserver.com')

    for j in ${nameserver[@]}
       do
          IPADD=`dig $j $i +noall +answer | grep "A" | awk '{print $5}'`
          if [[ $IPADD =~ $regexp ]]
            then
                echo "IP Address = " $IPADD
                ServerName=`nslookup $IPADD | grep -o -P '(?&lt;=\=).*(?=.)'`
                echo "ServerName = " $ServerName
                DATA=`whois $IPADD | egrep 'org-name|OrgName' | awk '{print $2.$3}'`
                echo "Data Center = " $DATA
                break
          fi
       done
}

check2 ()
{
    Pinging=`ping $i -c 1 | grep 'from' | cut -d$' ' -f4-5| tr '\(|\)' ' '`
    IPADD=`awk '{print $2}' &lt;&lt;&lt; $Pinging`
    echo "IP Address = " $IPADD
    ServerName=`awk '{print $1}' &lt;&lt;&lt; $Pinging`
    echo "Server Name = " $ServerName
}

for i in ${HIP[@]} 
do
    echo "Domain Name = " $i;
    nsserver=`nslookup -type=ns $i | grep 'nameserver' |  grep -o -P '(?&lt;=ns.).*(?=.)' | head -n 1`
    if [[ $nsserver == 'cloudflare.com' ]]
    then
            check
        if ! [[ $IPADD =~ $regexp ]]
        then
                echo "This Domain does not belong to this server."
        fi
    else
        check2
    fi

    whois $i | grep "Registrant Name"
    nslookup -type=ns $i | grep nameserver | awk '{print $2,$3,$4}'
    var=`curl -sL $i | grep '&lt;title&gt;' | tr -d ' ' | grep -o -P '(?&lt;=Account).*(?=ed)'`
    if [[ $var == 'Suspend' ]]
        then
        echo "Status = Account Suspended"
        else
        var=`curl -I $i 2&gt;/dev/null | head -n 1 | cut -d$' ' -f2-3`
        echo "Status = " $var
    fi
    printf '%*s' 100 | tr ' ' '#'
    echo ''

done
Shellcheck reports quite a few issues you might want to correct:
shellcheck -f gcc  197939.sh
197939.sh:2:5: warning: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. [SC2124]
197939.sh:5:24: note: Backslash is literal in &quot;\.&quot;. Prefer explicit escaping: &quot;\\.&quot;. [SC1117]
197939.sh:5:36: note: Backslash is literal in &quot;\.&quot;. Prefer explicit escaping: &quot;\\.&quot;. [SC1117]
197939.sh:5:48: note: Backslash is literal in &quot;\.&quot;. Prefer explicit escaping: &quot;\\.&quot;. [SC1117]
197939.sh:8:14: error: Double quote array expansions to avoid re-splitting elements. [SC2068]
197939.sh:10:17: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:10:22: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:10:25: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:13:38: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:14:28: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:14:38: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:15:38: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:16:22: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:16:29: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:16:38: note: egrep is non-standard and deprecated. Use grep -E instead. [SC2196]
197939.sh:17:39: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:25:13: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:25:19: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:26:11: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:26:33: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:27:26: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:28:16: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:28:38: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:29:27: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:32:10: error: Double quote array expansions to avoid re-splitting elements. [SC2068]
197939.sh:34:27: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:35:14: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:35:33: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:47:11: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:48:23: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:49:9: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:49:19: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:54:13: note: Use $(..) instead of legacy `..`. [SC2006]
197939.sh:54:22: note: Double quote to prevent globbing and word splitting. [SC2086]
197939.sh:55:26: note: Double quote to prevent globbing and word splitting. [SC2086]

Additionally, I recommend making regexp, nameserver, IPADD, ServerName and DATA local within check() (and giving most of them better names, or inlining the single-use ones), and making Pinging, IPADD and ServerName local within check2():
check ()
{
    local regexp='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
    local nameserver=('@ns1.ournameserver.com' '@ns2.ournameserver.com' '@ns3.ournameserver.com')

    for j in &quot;${nameserver[@]}&quot;
    do
        local IPADD
        IPADD=$(dig &quot;$j&quot; &quot;$i&quot; +noall +answer | grep &quot;A&quot; | awk '{print $5}')
        if [[ $IPADD =~ $regexp ]]
        then
            echo &quot;IP Address = $IPADD&quot;
            echo &quot;ServerName = $(nslookup &quot;$IPADD&quot; | grep -o -P '(?&lt;=\=).*(?=.)')&quot;
            echo &quot;Data Center = $(whois &quot;$IPADD&quot; | grep -E 'org-name|OrgName' | awk '{print $2.$3}')&quot;
            break
        fi
    done
}

check2 ()
{
    local Pinging
    Pinging=$(ping &quot;$i&quot; -c 1 | grep 'from' | cut -d$' ' -f4-5| tr '\(|\)' ' ')
    echo &quot;IP Address = $(awk '{print $2}' &lt;&lt;&lt;&quot;$Pinging&quot;)&quot;
    echo &quot;Server Name = $(awk '{print $1}' &lt;&lt;&lt;&quot;$Pinging&quot;)&quot;
}

Prefer to pass &quot;$i&quot; as an argument to check(), rather than communicating via global variables.  And communicate the $IPADD from the last successful nameserver by other means.
Instead of extracting substrings using grep, then testing them with [[ =~ ]], simply use grep -q for the test.
Improved code
There's still plenty left to work on (for example, repeated whois invocations).
#!/bin/bash

check ()
{
    local regexp='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
    local nameserver=('ns1.ournameserver.com' 'ns2.ournameserver.com' 'ns3.ournameserver.com')

    for j in &quot;${nameserver[@]}&quot;
    do
        local IPADD
        IPADD=$(dig &quot;@$j&quot; &quot;$1&quot; +noall +answer | grep -w 'A' | awk '$4==&quot;A&quot; {print $5}')
        if [[ $IPADD =~ $regexp ]]
        then
            echo &quot;IP Address = $IPADD&quot;
            echo &quot;ServerName = $(nslookup &quot;$IPADD&quot; | grep -o -P '(?&lt;=\=).*(?=.)')&quot;
            echo &quot;Data Center = $(whois &quot;$IPADD&quot; | grep -E 'org-name|OrgName' | awk '{print $2.$3}')&quot;
            return 0
        fi
    done
    return 1
}

check2 ()
{
    local Pinging
    Pinging=$(ping &quot;$1&quot; -c 1 | grep 'from' | cut -d$' ' -f4-5| tr '()' ' ')
    echo &quot;IP Address = $(awk '{print $2}' &lt;&lt;&lt;&quot;$Pinging&quot;)&quot;
    echo &quot;Server Name = $(awk '{print $1}' &lt;&lt;&lt;&quot;$Pinging&quot;)&quot;
}

for i in &quot;$@&quot;
do
    echo &quot;Domain Name = $i&quot;
    if nslookup -type=ns &quot;$i&quot; | grep -q 'nameserver.*cloudflare.com'
    then
        check &quot;$i&quot; || echo &quot;This Domain does not belong to this server.&quot;
    else
        check2 &quot;$i&quot;
    fi

    whois &quot;$i&quot; | grep &quot;Registrant Name&quot;
    nslookup -type=ns &quot;$i&quot; | grep nameserver | awk '{print $2,$3,$4}'
    if curl -sL &quot;http://$i&quot; | grep -q '&lt;title&gt;.*Account.*Suspended'
    then
        echo &quot;Status = Account Suspended&quot;
    else
        echo &quot;Status = $(curl -I &quot;$i&quot; 2&gt;/dev/null | head -n 1 | cut -d$' ' -f2-3)&quot; 
    fi
    printf '%*s\n' 100 | tr ' ' '#'
done