Skip to content

Instantly share code, notes, and snippets.

@g8d3
Created August 21, 2026 18:07
Show Gist options
  • Select an option

  • Save g8d3/daa912146898a6c7c1fda6fc0c874774 to your computer and use it in GitHub Desktop.

Select an option

Save g8d3/daa912146898a6c7c1fda6fc0c874774 to your computer and use it in GitHub Desktop.
conn() {
local H1="${1:?Suministra al menos un host}"
local H2="${2:-$1}"
local MOD="${3:-hibrido}"
local H="$H1"
while true; do
local INICIO=$SECONDS
echo "--- Conectando a $H (tmux: main) ---"
ssh -o ConnectTimeout=4 -o ConnectionAttempts=1 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -t "$H" "tmux new -A -s main"
# Se calcula la duración INMEDIATAMENTE después de salir de SSH
local DURACION=$(( SECONDS - INICIO ))
echo -e "\nIntento finalizado en $H. Duración SSH: ${DURACION}s."
# La pausa del menú ocurre después del cálculo de tiempo
[[ "$MOD" == "enter" ]] && read -r
[[ "$MOD" == "tiempo" ]] && sleep 3
[[ "$MOD" == "hibrido" ]] && read -r -k 1 -t 3
# Alterna entre host 1 y host 2
[[ "$H" == "$H1" ]] && H="$H2" || H="$H1"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment