-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshm.sh
executable file
·112 lines (100 loc) · 1.97 KB
/
sshm.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
command=$1
path=~/.ssh/sshm/
add(){
read -r -p "server name: " server_name
read -r -p "server host: " server_host
read -r -p "server port(22): " server_port
read -r -p "server user(root): " server_user
read -r -p "server password: " server_password
if [[ -z "$server_name" || -z "$server_host" ]]
then
echo "server_name or server_host does not exist"
exit;
fi
server_port=${server_port:-22}
server_user=${server_user:-"root"}
if [ ! -d $path ]
then
( mkdir $path )
fi
if [ ! -f $path$server_name ]
then
( touch $path$server_name )
else
read -r -p "server_name [$server_name] already exists, overwrite [o] or enter new server_name: " action
if [ ! $action ]
then
exit
fi
if [ $action == "o" ]
then
echo "" > $path$server_name
else
if [ $server_name == $action ]
then
echo "server_name already exists!"
exit
else
server_name=$action
fi
fi
fi
echo "server_name = $server_name" >> $path$server_name
echo "server_host = $server_host" >> $path$server_name
echo "server_port = $server_port" >> $path$server_name
echo "server_user = $server_user" >> $path$server_name
echo "server_password = $server_password" >> $path$server_name
}
ls(){
for file in $path*
do
while read line
do
eval "$line"
done < $file
echo "`basename $file`: $server_host"
unset server_host
done
}
login(){
if [ ! -f $path$1 ]
then
echo "server_name [$1] does not exist"
exit
fi
while read line
do
eval "$line"
done < $path$1
expect -c'
spawn ssh -p '$server_port' '$server_user'@'$server_host'
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*assword:" { send "'$server_password'\r" }
}
interact
'
}
delete(){
read -r -p "do you want to delete [y] ?" action
if [ "$action"x == "y"x ]
then
rm -rf $path$1
fi
exit
}
case $command in
(add)
add
;;
(ls)
ls
;;
(rm)
delete $2
;;
(*)
login $command
;;
esac