while read line
do
user=`echo $line | cut -d " " -f 2`
ip=`echo $line | cut -d " " -f 1`
passwd=`echo $line | cut -d " " -f 3`
expect <<EOF
set timeout 10
spawn ssh-copy-id $user@$ip
expect {
"yes/no" { send "yes
";exp_continue }
"password" { send "$passwd
" }
}
expect "password" { send "$passwd
" }
EOF
done < hosts