forked from RichardCao/logging-for-openstack-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopysshkey.sh
executable file
·49 lines (44 loc) · 1.03 KB
/
copysshkey.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
#!/usr/bin/expect
set timeout 20
log_user 0
if { $argc != 3 } {
send_user "\n$argv0 <user> <ip> <passwd>\n\n"
exit 1
}
set user [lindex $argv 0]
set ip [lindex $argv 1]
set passwd [lindex $argv 2]
set sendpasswd 0
spawn ssh-copy-id $user@$ip
while 1 {
expect {
"Are you sure you want to continue connecting" {
send "yes\r"
}
"*assword" {
send "$passwd\r"
set sendpasswd 1
}
"exist" {
send_user "\[INFO\]The key already exists on remote system, try to login with \"ssh $user@$ip\"\n"
exit
}
"Number of key(s) added" {
send_user "\[INFO\]The key is installed successfully! Try to login with \"ssh $user@$ip\"\n"
exit
}
"Host is down" {
send_user "\[INFO\]The remote host $ip is down...Try to contact the cluster admin...\n"
exit 1
}
timeout {
if { $sendpasswd == 0 } {
send_user "\[INFO\]The remote $ip host can't be accessed now!\n"
} else {
send_user "\[INFO\]The key is not installed on remote host $ip...Try to contact the cluster admin...\n"
}
exit 1
}
}
}
expect eof