0
I have two CNAMEs and want to verify if they point to the same IP. What is the best way to do it?
Input file:
cname1 cname2
cname3 cname4
...
Here is the code I have written:
#!/bin/bash
while read -r cname1 cname2; do
ip1=$(dig +short "$cname1" | tail -1)
ip2=$(dig +short "$cname2" | tail -1)
[[ $ip1 != $ip2 ]] && printf '%s\n' "$cname1 and $cname2 differ: $ip1 $ip2"
done < cnames.txt
Is there a more efficient and robust way to do this?
What do you mean by "better"? If you mean shorter, try https://codegolf.stackexchange.com/ .
– Christopher Hostage – 2018-10-31T22:56:15.893Why not use "nslookup" and "ping"? – S.Leon – 2018-11-01T13:40:02.150