-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-multi.sh
executable file
·56 lines (54 loc) · 1.39 KB
/
ssh-multi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# a script to ssh multiple servers over multiple tmux panes
# -c is use ssh config file to provide user login info
starttmux() {
if [ $config != "Y" ];then
tmux new-window "ssh -l $user $port $key -o StrictHostKeyChecking=no `sed -n '1p' $iplist`"
else
tmux new-window "ssh -o StrictHostKeyChecking=no `sed -n '1p' $iplist`"
fi
unset hosts[0];
for i in `sed -n '2,$p' $iplist`;
do
if [ $config == "Y" ];then
tmux split-window -h "ssh -o StrictHostKeyChecking=no $i"
else
tmux split-window -h "ssh -o StrictHostKeyChecking=no -l $user $port $key $i"
fi
tmux select-layout tiled > /dev/null
done
tmux select-pane -t 0
tmux set-window-option synchronize-panes on > /dev/null
}
FLAG=0
user=`whoami`
port=''
config='N'
while getopts "hci:l:p:a:" Option
do
case $Option in
i) key="-i $OPTARG"
if [ $OPTARG == "NULL" ];then
key=""
fi
;;
p) port='-p '$OPTARG;;
l) user=$OPTARG;;
c) config="Y";;
a) iplist=$OPTARG
FLAG=1
;;
h)
echo -e "\033[01;31mUsage:$0 [-c] [-l user] [-p port] [-i identify_key|NULL] -a ip_list_file \033[0m"
exit 2
;;
esac
done
if [ $FLAG -eq 1 ]
then
HOSTS=`cat $iplist`
else
echo -e "please use \033[01;31m -a ip_list_file \033[0m to ip or hostname list"
exit 1
fi
starttmux