Tmux multiple ssh connections with synchronized panels

If need to debug/check in real-time multiple servers via ssh, this can be used.

tmux script

#!/bin/sh

TARGET="tmux-ssh"
SSH_USER="devops"

i=0
while read line
do
    if [ $i == 0 ]
    then
        tmux new-window -a -n ${TARGET} "ssh -l ${SSH_USER} ${line}"
    else
        tmux split-window -t "${TARGET}" "ssh -l ${SSH_USER} ${line}" && \
            tmux select-layout -t "${TARGET}" tiled
    fi
    let i++
done < "${1:-/dev/stdin}"
tmux set-window-option -t ${TARGET} synchronize-panes on

hosts

If the input is json, jq can be used to extract hosts, assuming your output is similar to:

  "serverA": {
    "hosts": [
      "127.20.23.24",
      "127.20.12.37",
      "127.50.10.21",
      "127.50.13.20"
    ]
  },
  "serverB": {
    "hosts": [
      "127.20.23.116",
      "127.50.10.39"
    ]
  },
  "serverC": {
    "hosts": [
      "127.20.8.9",
      "127.50.16.130"
    ]
  }

To get only the hosts and ssh into them you could do something like:

cat hosts | jq ".serverA.hosts[]" -r | tmux-ssh.sh