blob: fc837f1ecaf862de4cd7b6e8c0a67523d26d56f5 (
plain)
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
|
#!/usr/bin/expect -f
proc setup_pwl_ssh { host pw1 pw2 } {
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$host
set timeout 50
expect {
"yes/no" {
send "yes\r"
exp_continue
} "password: " {
send "$pw1\r"
expect {
"#" {
# Success. Nothing to do
} "password: " {
send "$pw2\r";
expect {
"#" {
# Success. Nothing to do
} (.*) {
catch {close -i $spawn_id}
wait -nowait -i $spawn_id
}
}
}
}
} timeout {
catch {close -i $spawn_id}
wait -nowait -i $spawn_id
} eof {
}
}
}
if { $argc < 2 } {
puts "usage $argv0 <logfile> <list-of-hosts>"
exit
}
log_user 0
set logfile [ lindex $argv 0 ]
exp_log_file -a -noappend $logfile
set pw1 $env(ROOT_PW1)
set pw2 $env(ROOT_PW2)
for {set i 1} {$i<[llength $argv]} {incr i} {
set host [lindex $argv $i]
setup_pwl_ssh $host $pw1 $pw2
}
|