testing/guestbin/wait-until-alive
raw| 1 | #!/bin/sh |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | if test $# -lt 1; then |
| 6 | cat 1>&2 <<EOF |
| 7 | Usage: $0 <dest> [ -I <interface> ] |
| 8 | EOF |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | # Run ping so that it exits with success the moment it gets a single |
| 13 | # packet pack. |
| 14 | ping="ping -n -c 1 -w 4 $@" |
| 15 | |
| 16 | if output=$($ping 2>&1); then |
| 17 | echo "destination $@ is alive" |
| 18 | exit 0 |
| 19 | else |
| 20 | echo "$ping" |
| 21 | echo "$output" |
| 22 | echo "destination $@ is dead" |
| 23 | exit 1 |
| 24 | fi |