Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/expect -f
- set timeout 5
- set ip_cnt 0
- log_user 0
- puts ">>> Start adding keys <<<"
- set fh [open [lindex $argv 0]]
- while {[gets $fh line] >= 0} {
- set info [ split $line ]
- set ip [ lindex $info 0 ]
- set passwd [ lindex $info 1 ]
- puts -nonewline [format "#%-3d adding keys for %-15s ...... " [incr ip_ct] $ip]
- flush stdout
- spawn -noecho ssh-copy-id root@$ip
- expect {
- timeout { puts "time out" }
- "yes/no" {
- send "yes\r"
- expect "password:" { send "$passwd\r" }
- }
- "password:" {
- send "$passwd\r"
- expect {
- "key(s) added: " { puts "success" }
- "Permission denied" { puts "wrong password"; send "\003" }
- }
- }
- "skipped" { puts "already installed!" }
- }
- }
- close $fh
- puts ">>> Done <<<"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement