I am trying to get list of all hostnames from my DNS server by command:
host -l example-domain.com mydns.comHowever one machine has invalid DNS name, because there are two hyphens in row and I get error:
host: 'exa--mple.example-domain.com' is not a legal IDNA2008 name.....In this case executing of this command is interrupted and I don't get complete list. Is there any way how to skip this error, and get complete list? Or maybe some other command? I have also tried dig command, but there is same problem:
dig @mydns.com example-domain.com axfrSomething like "try/catch" would be fine, but I think it doesn't exist in bash. I have also tried export IDN_DISABLE=1 according to manual of command host. Unfortunately, it doesn't help me, still same error. I am using current version of debian.
2 Answers
Yes, it is possible to send all occurring errors "to the trash" by using
command > /dev/null 2>&1or
command &>/dev/nullFor more detailed information visit e.g. cyberciti or do a quick google search, then you will probably find more detailed tutorials.
1Commands which are part of the bash syntax, have to be right in a script. But you are speaking about the result of the execution of a program called by this bash script. $? is the value returned by the last executed command. You can use it to make decisions in the following part of the bash script. Unfortunately, according to man pages of the host and dig commands, there is no useful code returned.
You have the general capability to redirect the output of the dig or host commands and to analyze it using commands like grep or awk. But you are depending on the exact syntax of the output of these programs. This syntax can change in future releases of these programs.
Please note a discrepancy in your question. Your host command is asking about example-domain.com and the cited output is related to exa--mple.com. Further, it is better to always ask about absolute domain names, i.e. ending with a period.