How to make ping more persistent with unresolved hostnames

2

When I try to ping a hostname of a computer that is down, I get en error that it cannot resolve the hostname.

$ alice:~ me$ ping bob
ping: cannot resolve bob: Unknown host

Is there a way I can make ping more persistent? I want it to keep trying so I can see when bob comes back online.

Svish

Posted 2010-12-15T01:32:30.910

Reputation: 27 731

1Do you expect the name to resolve when the host comes up? – Ignacio Vazquez-Abrams – 2010-12-15T03:40:51.017

1@Ignacio: Yes, that's what I expect. And it does. – Svish – 2010-12-15T18:35:43.443

Answers

1

a)

while true; do
    ping bob || sleep 1
done

or

until ping bob; do
    sleep 1
done

or b) Configure a name resolution method that doesn't rely on the target host being up. /etc/hosts for the lazy.

user1686

Posted 2010-12-15T01:32:30.910

Reputation: 283 655

Nice and simple, I like it. – Svish – 2010-12-15T18:36:55.300

redirect stderr to /dev/null if you don't want unknown host spam – Michael – 2013-11-06T19:43:53.610