0

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?

cs.lev
  • 1
  • 13 is Carriage Return aka CR aka ^M. It comes from editing files on Windows. See duplicate on how to remove it. – muru Feb 02 '24 at 07:31
  • Was mydomains.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 with od -a mydomains.csv ought to show you the whitespace characters along with the printing ones. – Sotto Voce Feb 02 '24 at 07:31
  • I don't know if the original file was edited on windows or not, but even if I create a file from scratch, the same thing happens. The duplicate does not really solve my problem.
    od -a mydoamins.csv
    0000000   1   ,   g   o   o   g   l   e   .   c   o   m  cr  nl
    0000016
    

    I was editing with nano

    – cs.lev Feb 02 '24 at 07:36
  • My bad, even though it was edited from scratch on Linux using nano, it still had that problem. Irrespectively, the dos2unix command make it appropriate for me. Thanks – cs.lev Feb 02 '24 at 07:40

0 Answers0