Avoid dig errors if not connected to a network
This commit is contained in:
parent
c4755124a0
commit
d113d710a7
1 changed files with 6 additions and 4 deletions
|
|
@ -11,10 +11,12 @@ IP="$(ip a show scope global \
|
||||||
| grep inet \
|
| grep inet \
|
||||||
| head -1 \
|
| head -1 \
|
||||||
| sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')"
|
| sed -r 's#.*inet ([0-9]+.[0-9]+.[0-9]+.[0-9]+.)/.*#\1#')"
|
||||||
HOSTNAME="$(dig +noall +answer +short -x "$IP" \
|
if [[ "${IP:+x}" ]]; then
|
||||||
| grep -v ';' \
|
HOSTNAME="$(dig +noall +answer +short -x "$IP" \
|
||||||
| head -1 \
|
| grep -v ';' \
|
||||||
| sed 's/\.$//')"
|
| head -1 \
|
||||||
|
| sed 's/\.$//')"
|
||||||
|
fi
|
||||||
|
|
||||||
# Set hostname
|
# Set hostname
|
||||||
if [[ "${HOSTNAME:+x}" ]]; then
|
if [[ "${HOSTNAME:+x}" ]]; then
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue