Created
October 14, 2025 00:35
-
-
Save raghavauppuluri13/c0f84aa1495e7ea921cca27df5615a01 to your computer and use it in GitHub Desktop.
Revisions
-
raghavauppuluri13 revised this gist
Oct 14, 2025 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,11 +12,11 @@ TRIES=10 host_for() { printf "bracketbot-%s.local" "$1"; } ping_01s() { local host="$1" # Linux: -W (ms) with iputils ping; macOS/FreeBSD: -W (ms) also works for recent versions. # Fallback to BSD-style: -t (ttl) + short sleep guard. if ping -c1 -W 100 "$host" >/dev/null 2>&1; then return 0 fi # Try BSD-ish variant if first failed quickly (option-wise) @@ -30,7 +30,7 @@ try=0 while (( try < TRIES )); do host="$(host_for "$ID")" echo "[bbssh] Probing ${host} (attempt $((try+1))/$TRIES)..." if ping_01s "$host"; then echo "[bbssh] Host is up: $host" exec ssh "bracketbot@${host}" "$@" fi -
raghavauppuluri13 created this gist
Oct 14, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/usr/bin/env bash # bbssh: try bracketbot-<ID>.local, auto-increment ID up to 10 tries, then ssh on success set -euo pipefail if [[ $# -lt 1 ]]; then echo "Usage: $0 <ID> [ssh-args...]" >&2 exit 1 fi ID="$1"; shift || true TRIES=10 host_for() { printf "bracketbot-%s.local" "$1"; } ping_05s() { local host="$1" # Linux: -W (ms) with iputils ping; macOS/FreeBSD: -W (ms) also works for recent versions. # Fallback to BSD-style: -t (ttl) + short sleep guard. if ping -c1 -W 500 "$host" >/dev/null 2>&1; then return 0 fi # Try BSD-ish variant if first failed quickly (option-wise) if ping -c1 -t 1 "$host" >/dev/null 2>&1; then return 0 fi return 1 } try=0 while (( try < TRIES )); do host="$(host_for "$ID")" echo "[bbssh] Probing ${host} (attempt $((try+1))/$TRIES)..." if ping_05s "$host"; then echo "[bbssh] Host is up: $host" exec ssh "bracketbot@${host}" "$@" fi echo "[bbssh] No response within 0.5s. Incrementing ID." # Increment while preserving any leading zeros (e.g., 001 -> 002) if [[ "$ID" =~ ^0*[0-9]+$ ]]; then width=${#ID} num=$((10#$ID + 1)) printf -v ID "%0${width}d" "$num" else # If not purely numeric, just append +1 ID="${ID}1" fi ((try++)) done echo "[bbssh] Gave up after $TRIES attempts." >&2 exit 1