I find myself frequently tasked with updating DNS records and needing to know exactly when the refresh will begin (a.k.a TTL expiration). I came up with this bash one-liner that gives me the output I want:
$ dig +noall +answer www.google.com | \
> awk '{ print $2 }' | \
> { read secs; echo "`expr $secs / 60`m `expr $secs % 60`s remaining ($secs)"; }
output:
3m 36s remaining (216)
I'd like to be able to wrap the watch
command around this so that I can leave it running in a terminal and get a live countdown. Something like:
$ watch -n 10 "dig +noall +answer www.google.com | \
> awk '{ print $2 }' | \
> { read secs; echo '`expr $secs / 60`m `expr $secs % 60`s remaining ($secs)'; }"
But this simply results in a non-functional watch instance followed by:
expr: syntax error
I am pretty sure this is some kind of piping/quoting problem and I'm not that well-versed on the intricacies. For the sake of portability I'd prefer to keep it as a one-liner vs. resorting to a script that requires saving to disk. Does anyone know the right way to accomplish this?