I'm using following script to dig a domain on multiple servers. But if a domain does not exist then also the output is "Resolved by server: domain.com ;". It just because the execution of the command returns 0 . Can any one help me if there are not records this should inform correct statement instead of printing wrong statement.
#!/bin/bash
a=$1
go="8.8.8.8"
f2="4.2.2.2"
if [ "$a" = "" ]
then
echo "Usage: `basename $0` domain.com"
exit 1
else
dig @"$go" "$a" +short
if [ "$?" != 0 ]
then
echo "Server: $go did not resolve: $a ; "
else
echo "Resolved by $go: $a ; "
echo " "
fi
fi
if [[ -z $(dig @"$go" "$a" +short) ]] worked for me thanks :)
dig is a tool to check for problems on a DNS server, since a NXDOMAIN is not a problem it will return 0.
dig will throw other codes e.g. when the server is down, the query is refused...
Switch to a different tool like host:
Instead of:
try: