mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
41 lines
556 B
Bash
Executable File
41 lines
556 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
|
|
|
|
wait_for_host_down()
|
|
{
|
|
local host=$1
|
|
|
|
echo "Waiting for $host to go down..."
|
|
|
|
while ping -c 1 -W 1 "$host" > /dev/null 2>&1; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
main()
|
|
{
|
|
local host=$1
|
|
shift
|
|
|
|
wait_for_host_down "$host"
|
|
|
|
"$@"
|
|
}
|
|
|
|
main "$@"
|