147 lines
2.5 KiB
Bash
Executable File
147 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
SESSION="cs425-debug"
|
|
NUM_SERVERS=10
|
|
|
|
WORKDIR="fa26_cs425_.group-mp_.team-01/MP2"
|
|
FORMATTER="$(cd "$(dirname "$0")" && pwd)/pretty_membership.py"
|
|
|
|
SSH_OPTS="-o ConnectTimeout=2 \
|
|
-o ServerAliveInterval=1 \
|
|
-o ServerAliveCountMax=1 \
|
|
-o BatchMode=yes"
|
|
|
|
|
|
# RESET TMUX
|
|
|
|
|
|
tmux kill-session -t "$SESSION" 2>/dev/null || true
|
|
|
|
tmux new-session -d -s "$SESSION" -n "display"
|
|
|
|
tmux set-option -t "$SESSION" pane-border-status top
|
|
tmux set-option -t "$SESSION" pane-border-format " #{pane_title} "
|
|
|
|
|
|
# DISPLAY COMMAND
|
|
|
|
|
|
make_display_cmd() {
|
|
local vm="$1"
|
|
|
|
cat <<EOF
|
|
clear; while true; do
|
|
printf '\033[H'
|
|
|
|
{
|
|
ssh $SSH_OPTS server$vm \
|
|
'FILE="\$HOME/$WORKDIR/membership_list.txt";
|
|
if [ ! -f "\$FILE" ]; then
|
|
echo "**STOPPED** no membership file";
|
|
else
|
|
NOW=\$(date +%s);
|
|
MTIME=\$(stat -c %Y "\$FILE" 2>/dev/null || echo 0);
|
|
AGE=\$((NOW - MTIME));
|
|
|
|
if [ "\$AGE" -gt 3 ]; then
|
|
echo "**STOPPED** \${AGE}s since last update";
|
|
else
|
|
cat "\$FILE";
|
|
fi;
|
|
fi' 2>&1 \
|
|
|| echo "**STOPPED** SSH unavailable"
|
|
} | python3 "$FORMATTER"
|
|
|
|
printf '\033[J'
|
|
sleep 0.75
|
|
done
|
|
EOF
|
|
}
|
|
|
|
|
|
# DISPLAY WINDOW
|
|
|
|
|
|
tmux select-pane \
|
|
-t "$SESSION:display.0" \
|
|
-T "VM1"
|
|
|
|
tmux send-keys \
|
|
-t "$SESSION:display.0" \
|
|
"$(make_display_cmd 1)" \
|
|
C-m
|
|
|
|
for i in $(seq 2 "$NUM_SERVERS"); do
|
|
|
|
PANE=$(
|
|
tmux split-window \
|
|
-t "$SESSION:display" \
|
|
-P \
|
|
-F '#{pane_id}'
|
|
)
|
|
|
|
tmux select-layout \
|
|
-t "$SESSION:display" \
|
|
tiled
|
|
|
|
tmux select-pane \
|
|
-t "$PANE" \
|
|
-T "VM$i"
|
|
|
|
tmux send-keys \
|
|
-t "$PANE" \
|
|
"$(make_display_cmd "$i")" \
|
|
C-m
|
|
done
|
|
|
|
tmux select-layout \
|
|
-t "$SESSION:display" \
|
|
tiled
|
|
|
|
|
|
# COMMAND WINDOW
|
|
|
|
|
|
tmux new-window \
|
|
-t "$SESSION" \
|
|
-n "cmds"
|
|
|
|
tmux set-window-option \
|
|
-t "$SESSION:cmds" \
|
|
pane-base-index 0
|
|
|
|
tmux select-pane \
|
|
-t "$SESSION:cmds.0" \
|
|
-T "VM1"
|
|
|
|
for i in $(seq 2 "$NUM_SERVERS"); do
|
|
|
|
PANE=$(
|
|
tmux split-window \
|
|
-t "$SESSION:cmds" \
|
|
-P \
|
|
-F '#{pane_id}'
|
|
)
|
|
|
|
tmux select-layout \
|
|
-t "$SESSION:cmds" \
|
|
tiled
|
|
|
|
tmux select-pane \
|
|
-t "$PANE" \
|
|
-T "VM$i"
|
|
done
|
|
|
|
tmux select-layout \
|
|
-t "$SESSION:cmds" \
|
|
tiled
|
|
|
|
|
|
# OPEN DISPLAY
|
|
|
|
|
|
tmux select-window \
|
|
-t "$SESSION:display"
|
|
|
|
tmux attach-session \
|
|
-t "$SESSION" |