Script error with when input is empty
Hi,
I created the following shell script to lookup multiple name servers for a domain.
Code:
#!/bin/bash
echo -n "Enter the domain name and press [ENTER]: "
read domain
result1=`dig +short $domain @4.2.2.1`
revresult1=`host $result1 | cut -f5 -d " "`
echo "test1"
result2=`dig +short $domain @dns1.vistapages.com`
revresult2=`host $result2 | cut -f5 -d " "`
echo "test2"
result3=`dig +short $domain @dns2.vistapages.com`
revresult3=`host $result3 | cut -f5 -d " "`
echo "test3"
result4=`dig +short $domain @ns1.hostmds.com`
revresult4=`host $result4 | cut -f5 -d " "`
echo "test4"
result5=`dig +short $domain @ns1.hostmds.com`
revresult5=`host $result5 | cut -f5 -d " "`
echo "test5"
result6=`dig +short $domain @dns1.hostingplex.com`
revresult6=`host $result6`
echo "test6"
result7=`dig +short $domain @dns2.hostingplex.com`
revresult7=`host $result7`
echo "test7"
echo "================================="
echo " Result at Verizon DNS : $result1"
echo " Reverse at Verizon DNS : $revresult1"
echo "================================="
echo " Result at dns1.vistapages.com : $result2"
echo " Reverse at dns1.vistapages.com : $revresult2"
echo "================================="
echo " Result at dns2.vistapages.com : $result3"
echo " Reverse at dns2.vistapages.com : $revresult3"
echo "================================="
echo " Result at ns1.hostmds.com : $result4"
echo " Reverse at ns1.hostmds.com : $revresult4"
echo "================================="
echo " Result at ns2.hostmds.com : $result5"
echo " Reverse at ns2.hostmds.com : $revresult5"
echo "================================="
echo " Result at dns1.hostingplex.com : $result6"
echo " Reverse at dns1.hostingplex.com : $revresult6"
echo "================================="
echo " Result at dns2.hostingplex.com : $result7"
echo " Reverse at dns2.hostingplex.com : $revresult1"
But when the dns server do not have any result the script generates error.
Code:
Enter the domain name and press [ENTER]: test.com
test1
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
[-R number] hostname [server]
-a is equivalent to -v -t *
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N changes the number of dots allowed before root lookup is done
-r disables recursive processing
-R specifies number of retries for UDP packets
-t specifies the query type
-T enables TCP/IP mode
-v enables verbose output
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
-s a SERVFAIL response should stop query
test2
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
[-R number] hostname [server]
-a is equivalent to -v -t *
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N changes the number of dots allowed before root lookup is done
-r disables recursive processing
-R specifies number of retries for UDP packets
-t specifies the query type
-T enables TCP/IP mode
-v enables verbose output
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
-s a SERVFAIL response should stop query
test3
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
[-R number] hostname [server]
-a is equivalent to -v -t *
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N changes the number of dots allowed before root lookup is done
-r disables recursive processing
-R specifies number of retries for UDP packets
-t specifies the query type
-T enables TCP/IP mode
-v enables verbose output
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
-s a SERVFAIL response should stop query
test4
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
[-R number] hostname [server]
-a is equivalent to -v -t *
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-i IP6.INT reverse lookups
-N changes the number of dots allowed before root lookup is done
-r disables recursive processing
-R specifies number of retries for UDP packets
-t specifies the query type
-T enables TCP/IP mode
-v enables verbose output
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
-s a SERVFAIL response should stop query
test5
test6
test7
=================================
Result at Verizon DNS : 205.178.152.103
Reverse at Verizon DNS : w2k3-cfm3.prod.netsolhost.com.
=================================
Result at dns1.vistapages.com :
Reverse at dns1.vistapages.com :
=================================
Result at dns2.vistapages.com :
Reverse at dns2.vistapages.com :
=================================
Result at ns1.hostmds.com :
Reverse at ns1.hostmds.com :
=================================
Result at ns2.hostmds.com :
Reverse at ns2.hostmds.com :
=================================
Result at dns1.hostingplex.com : 208.83.209.12
Reverse at dns1.hostingplex.com : 12.209.83.208.in-addr.arpa domain name pointer 208-83-209-12.mdswireless.com.
=================================
Result at dns2.hostingplex.com : 208.83.209.12
Reverse at dns2.hostingplex.com : w2k3-cfm3.prod.netsolhost.com.
How can I get rid of these errors.
|