#! /usr/bin/env bash set -euo pipefail declare username host key_file ssh_opts readarray -t ssh_opts < <(echo "$ssh_opts" | jq -r '.[]') sshOpts=( -o BatchMode=yes \ -o StrictHostKeyChecking=no \ -o ConnectTimeout=5 \ -o ServerAliveInterval=5 \ ) if [[ -n "${key_file}" ]]; then sshOpts+=( -i "${key_file}" ) fi for ssh_opt in "${ssh_opts[@]}"; do sshOpts+=( -o "${ssh_opt}" ) done for i in $(seq 1 30); do if ssh "${sshOpts[@]}" "${username}@${host}" "true"; then exit 0 fi echo "Waiting for SSH (attempt #$i)..." sleep 5 done echo "SSH never came up!" >&2 exit 1