-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpect.sh
More file actions
executable file
·35 lines (28 loc) · 759 Bytes
/
expect.sh
File metadata and controls
executable file
·35 lines (28 loc) · 759 Bytes
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
#!/usr/bin/expect -f
# Usage: ./ssh-copy-id-expect.sh <user@host> <path_to_key> <password>
set userHost [lindex $argv 0]
set keyPath [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh-copy-id -f -i $keyPath $userHost
expect {
-re "(?i)yes/no" {
send "yes\r"
exp_continue
}
-re ".*'s password: *$" {
send "$password\r"
}
eof {
# No prompt appeared; probably key already installed
}
}
spawn ssh -o StrictHostKeyChecking=no -i $keyPath $userHost "echo 'SSH key installed successfully.'"
expect {
-re "*"SSH key installed successfully.*" {
send_user "SSH key installed successfully.\n"
}
eof {
send_user "Failed to install SSH key.\n"
exit 1
}
}