Files
dotfiles/local/bin/x-when-down
Ismo Vuorinen a708085dda Multiple scripts, go packages, shared configs...
Documentation, links, renaming files for clarity, and all that.
2022-12-19 17:19:00 +02:00

33 lines
456 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
"$@"