Aside from the fact that the code you posted does not compile
because the if/else is missing curlies, it seems as though
the dnscmd command is failing. You should print the value of $? so that you can get more information as to the cause of the failure.