Score:2

detect if zone transfer with dig succeed or not via return code

in flag

I have script like this

CHARSET=ASCII dig domain.com AXFR > domain.com.zone

if [ "$?" = "0" ]; then
    echo "OK"
else
    echo "Something went wrong"
    
fi

However, I saw there is non complete file with line at the end

;; communications error: end of file

Is there some bug in my script or how I can "catch" this error?

mx flag
You may already know this, but be aware that zone transfers are much less common now than when DNS was young. Any standard that refers to zone transfers, as the default way of moving DNS data in bulk, is ancient and should be distrusted. (Ignore me if you're just doing this between machines under your own control, or if up to date documentation has instructed you to use a zone transfer.)
in flag
I am aware. This is third party zone.
Score:2
by flag

The exit status ($?) of the dig command does not reflect whether the zone transfer was successful or not.

We could check the output file for the error message like that:

CHARSET=ASCII dig domain.com AXFR > domain.com.zone

if grep -q "communications error: end of file" domain.com.zone; then
    echo "Something went wrong"
else
    echo "OK"
    gzip -9 domain.com.zone
fi
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.