Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################################################################################################################
- # ssh wrapper to continuously retry if unavailable
- function ssh() {
- local opts=() end=0 host port cmds
- while [[ $1 ]]; do
- if ! ((end)); then
- case "$1" in
- -p) opts+=("$1" "$2"); port=$2; shift 2 ;;
- -*) opts+=("$1" "$2"); shift 2 ;;
- --) end=1; opts+=("$1"); shift ;;
- *) [[ ! ${host} ]] && host="$1" || cmds+=("$1"); shift ;;
- esac
- else
- opts+=("$1"); shift
- fi
- done
- [[ ${host} =~ @ ]] && { opts+=("-l" "${host%@*}"); host=${host##*@}; }
- echo "Waiting for ssh port '${port:=22}' on '${host}' to become available:"
- ( bash -c "exec {FD}<>/dev/tcp/${host}/${port}" ) &> /dev/null
- while [[ $? -ne 0 ]]; do
- sleep 2; ( bash -c "exec {FD}<>/dev/tcp/${host}/${port}" ) &> /dev/null
- done
- $(type -P ssh) "${opts[@]}" "${host}" "${cmds[@]}"
- }
- ########################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement