Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ########################################################################################################################
  2. # ssh wrapper to continuously retry if unavailable
  3. function ssh() {
  4. local opts=() end=0 host port cmds
  5. while [[ $1 ]]; do
  6. if ! ((end)); then
  7. case "$1" in
  8. -p) opts+=("$1" "$2"); port=$2; shift 2 ;;
  9. -*) opts+=("$1" "$2"); shift 2 ;;
  10. --) end=1; opts+=("$1"); shift ;;
  11. *) [[ ! ${host} ]] && host="$1" || cmds+=("$1"); shift ;;
  12. esac
  13. else
  14. opts+=("$1"); shift
  15. fi
  16. done
  17.  
  18. [[ ${host} =~ @ ]] && { opts+=("-l" "${host%@*}"); host=${host##*@}; }
  19.  
  20. echo "Waiting for ssh port '${port:=22}' on '${host}' to become available:"
  21. ( bash -c "exec {FD}<>/dev/tcp/${host}/${port}" ) &> /dev/null
  22. while [[ $? -ne 0 ]]; do
  23. sleep 2; ( bash -c "exec {FD}<>/dev/tcp/${host}/${port}" ) &> /dev/null
  24. done
  25.  
  26. $(type -P ssh) "${opts[@]}" "${host}" "${cmds[@]}"
  27. }
  28. ########################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement