0

I'm trying to check if my DNS TXT entry has propagated so I wrote this simple loop, but I'm getting an error from the host command and I've tried many different syntaxes but all seem wrong.

while [[ ($basednsentry != $basehost) ]]; do
    $basehost=$(host -t TXT "$basednsname")
      sleep 1m
done
sakumatto
  • 157
  • 1
  • 9
  • 2
    What error do you get? That would be necessary for solving your problem. – cramopy Oct 18 '17 at 05:17
  • Also cross check if you have host utility installed on your machine. which host – abhishek phukan Oct 18 '17 at 05:19
  • 2
    Remove the `$` before `basehost` on the second line. – codeforester Oct 18 '17 at 05:24
  • The error I get is runcertirenew.sh: line 32: =_acme-challenge.domain.com: command not found – sakumatto Oct 18 '17 at 05:29
  • That's not from the host command. – melpomene Oct 18 '17 at 05:32
  • I have installed host utiilty and the comman runs without issues from terminal – sakumatto Oct 18 '17 at 05:33
  • @codeforester I have declared basehost earlier, that's why I use the $ before it. However after taking it out, the code sems to work. Can you clarify why this is so and maybe add this as the answer so I can accept it? Thanks! – sakumatto Oct 18 '17 at 05:44
  • 2
    `$` is needed for expanding a variable, not for assignment. In your code, shell is interpreting the whole expression as a command because of the `$` at the beginning. Remove it and you will be good. See this post: https://stackoverflow.com/questions/2268104/command-not-found-error-in-bash-variable-assignment – codeforester Oct 18 '17 at 05:47
  • Be careful. If reassigning `basehost` is what you want, disregard my answer below. – Paul Hodges Oct 18 '17 at 15:27

1 Answers1

1

As per what @codeforester commented, the problem was the $ sign left of the variable. The $ is not for assignment, but for expanding a variable. Furthermore in the link @codeforester provided there was a simple tool mentioned that immediately found this error in my code: http://www.shellcheck.net/

the working code therefore is:

while [[ ($basednsentry != $basehost) ]]; do
    basehost=$(host -t TXT "$basednsname")
    sleep 1m
done
sakumatto
  • 157
  • 1
  • 9