I have a list of domains, and I want to use dig
to check whether those domains have HTTPS records or not. I ran a for loop to do so, and I realized that the reason why I don't have any result is because the domain name read from the file is suffixed with '\013' string when passed to dig
. Hence, I get NXDOMAIN (even for A records which are available for all the domains in my list).
My domain list is as follows:
google.com
cloudflare.com
I issue the following loop:
for i in $(cat mydomains.csv); do echo $i; dig $i; sleep 2; done
In the output, you can see that echo $i
shows google.com
for the first domain, but in the dig command's output, the requested domain is google.com\013
google.com
; <<>> DiG 9.18.18-0ubuntu0.22.04.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30386
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com\013. IN A
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Fri Feb 02 15:11:29 +08 2024
;; MSG SIZE rcvd: 40
I bet this is just some stupid encoding problem, but could not figure out how to overcome this. Anyone had the same issue before?
13
is Carriage Return akaCR
aka^M
. It comes from editing files on Windows. See duplicate on how to remove it. – muru Feb 02 '24 at 07:31mydomains.csv
created on a Windows computer? I'll bet it has a \013 (carriage return) character at the end of each line, and in your Linux that ends up appending the carriage return to the hostname at the end of each line in the file. Examining the file withod -a mydomains.csv
ought to show you the whitespace characters along with the printing ones. – Sotto Voce Feb 02 '24 at 07:31I was editing with nano
– cs.lev Feb 02 '24 at 07:36