V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  liuliancao  ›  全部回复第 10 页 / 共 10 页
回复总数  181
1  2  3  4  5  6  7  8  9  10  
2021-05-12 08:44:18 +08:00
回复了 blueorange 创建的主题 DevOps 推荐一款 ssh 终端
#!/usr/bin/env bash
# usage: ssh-multi for tmux by liuliancao at 2021/04/22 v1.
# a script to ssh multiple servers over multiple tmux panes
while getopts p:u:f: OPTION
do
case $OPTION in
p)PORT=$OPTARG;;
u)USER=$OPTARG;;
f)FILE=$OPTARG;;
?)echo "use ssh-multi -p $PORT -u $USER -f ssh-hosts-file" && exit 1;;
esac
done
index=-1

# split window to ssh
cat $FILE | while read host; do
index=$(($index + 1))
#if in tmux
if [[ -z $TMUX ]];then
in_tmux=0
[[ $index -eq 0 ]] && tmux new-session -d "ssh -p $PORT $USER@$host" && continue
tmux split-window -h "ssh -p $PORT $USER@$host"
# if not
else
in_tmux=1
[[ $index -eq 0 ]] && tmux new-window -n "ssh-multi" "ssh -p $PORT $USER@$host" && continue
tmux split-window -t "ssh-multi" "ssh -p $PORT $USER@$host"
fi
tmux select-layout tiled
done

tmux set-window-option synchronize-panes on

[[ in_tmux -eq 0 ]] && tmux a
1  2  3  4  5  6  7  8  9  10  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5840 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 02:04 · PVG 10:04 · LAX 18:04 · JFK 21:04
Developed with CodeLauncher
♥ Do have faith in what you're doing.