#!/usr/bin/env bash
#ssh-copy-id
rpm -q expect &>/dev/null
if [ $? -ne 0 ];then
yum -y install expect &>/dev/null
fi
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -P "" -f ~/.ssh/id_rsa
fi
while read ip
do
{
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
/usr/bin/expect <<-EOF
spawn ssh-copy-id root@$ip
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "123456\r" }
}
expect eof
EOF
fi
}&
done </ip.txt
wait
在/ip.txt文件中输入想要拷贝主机的ip以后运行以上脚本即可即可