#!/usr/bin/bash
password=123456
rpm -q expect &>/dev/null
if [ $? -ne 0 ];then
yum -y install expect
fi
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -P "" -f ~/.ssh/id_rsa
fi
for i in {10..16}
do
ip=10.88.15.$i
echo $ip
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh-copy-id $ip
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "$password\r" }
"*#" { send "ls\r" }
"*#" { send "exit\r" }
}
expect eof
EOF
done
wait
echo "finish..."