I'm trying to test some nameservers against a domain name.
For that, I created a script that reads a list of nameservers and asks for a domain name.
Something basic like this:
#!/bin/bash
domain=$1
[ -z $domain ] && read -p "DOMAIN NAME: " domain
namefile="./nameserver"
echo "RESULT - NAMESERVER DOMAIN IP"
for host in $(cat "$namefile"); do
IPADD=$(dig +short "$host" "$domain" A 2> /dev/null)
[[ ! -z $IPADD ]] && result="OK" || result="FAIL"
echo "$result - Nameserver: $host - Domain: $domain - IP answer: $IPADD"
done
The issue I'm having is that, when
Dig
fails, it is not redirecting errors to null
. Thus, the $IPADD
variable receives a wrong value.
# CORRECT nameserver
# dig +short @8.8.8.8 google.com A 2> /dev/null
142.250.218.206
---
# WRONG nameserver
# dig +short @8.8.8.80 google.com A 2> /dev/null
;; connection timed out; no servers could be reached
If I test it with a wrong nameserver address, I still get an error message, like shown above.
As I understand, when redirecting to null
, it should **not** display that error message.
Any idea?
Thank you.
Asked by markfree
(425 rep)
Nov 7, 2022, 11:55 PM
Last activity: Nov 9, 2022, 03:25 PM
Last activity: Nov 9, 2022, 03:25 PM