-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpush_key.sh
More file actions
31 lines (26 loc) · 771 Bytes
/
Copy pathpush_key.sh
File metadata and controls
31 lines (26 loc) · 771 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
#!/usr/bin/expect
set timeout 9
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]
if {[llength $argv] == 0} {
send_user "Usage: scriptname username \'password\' hostname\n"
exit 1
}
spawn ssh-copy-id -f -i /home/$username/.ssh/public_key.pub $username@$hostname
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for $hostname\n"; exit 1 }
"*re you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"*assword" {
send "$password\r"
send_user "\nPassword for hostname $hostname is correct\n"
}
}
expect {
timeout { send_user "\nLogin for hostname $hostname failed. Password incorrect.\n"; exit 1}
"*\$ "
}