#!/usr/bin/expect
set host_ip [lindex $argv 0]
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $host_ip
expect {
-timeout 60
"(yes/no)?" { send "yes\n";exp_continue}
"password:" { send "Ak46\n"}
timeout {puts "Connect timeout!";return}
}
expect eof
exit -onexit {
send_user "Job has finished!"
}
for ip in `cat /root/ip.txt`;do expect /root/fenfa_sshkey.exp $ip ;done