Files
dotfiles/local/bin/x-when-down
2023-03-27 10:01:02 +03:00

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
"$@"