Something went wrong. Try again.
Scaffolds custom tools for a devenv environment
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839#!/usr/bin/env bash# ssh-status: whether each host has an open SSH master connection.# With no hosts, the ones ssh-open recorded. Exits 1 if any is closed, so# `ssh-status HOST || ssh-open HOST` works in scripts.set -euo pipefail
case ${1:-} in -h | --help) echo "usage: ssh-status [HOST...] (no HOST: the hosts ssh-open opened)" exit 0 ;;esac
state="${XDG_RUNTIME_DIR:-$HOME/.cache}/devkit-ssh/hosts"if [ $# -eq 0 ]; then [ -s "$state" ] || { echo "ssh-status: no hosts opened with ssh-open" >&2; exit 0; } mapfile -t hosts <"$state"else hosts=("$@")fi
rc=0for host in "${hosts[@]}"; do out="$(ssh -O check "$host" 2>&1)" && open=1 || open=0 if [ "$open" = 1 ]; then pid="$(sed -n 's/.*pid=\([0-9]*\).*/\1/p' <<<"$out")" up="$(ps -o etime= -p "$pid" 2>/dev/null | tr -d ' ' || true)" printf '%-28s open pid %s%s\n' "$host" "$pid" "${up:+ up $up}" else case $out in *"No ControlPath"*) why=" (no ControlPath in ssh config)" ;; *) why="" ;; esac printf '%-28s closed%s\n' "$host" "$why" rc=1 fidoneexit "$rc"