mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
34 lines
453 B
Bash
Executable File
34 lines
453 B
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Wait until a given host is down (determined by ping) then execute the
|
|
# given command
|
|
#
|
|
# Usage:
|
|
# ./when-down HOST COMMAND...
|
|
#
|
|
# Example
|
|
# ./when-down 1.2.3.4 ssh 1.2.3.4
|
|
#
|
|
|
|
#
|
|
# Ensure we received the correct number of arguments.
|
|
#
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage: $0 HOST COMMAND..."
|
|
exit 1
|
|
fi
|
|
|
|
HOST=$1
|
|
|
|
echo "Waiting for $HOST to get down..."
|
|
|
|
true
|
|
while [ $? -ne 1 ]; do
|
|
ping -c 1 -W 1 "$HOST" > /dev/null
|
|
done
|
|
|
|
shift
|
|
|
|
"$@"
|
|
|