#!/usr/bin/env bash
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
以上是推送的脚本
下面是执行后的情况
spawn ssh-copy-id root@192.168.95.128
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/
id_rsa.pub"
The authenticity of host '192.168.95.128 (192.168.95.128)' can't be establishe
d.
ECDSA key fingerprint is SHA256:Uk4vyEhCsfA2b7rewb+IcjWA/3YHJyi4zNHobccNtgE.
ECDSA key fingerprint is MD5:e8:82:3b:89:63:bd:c8:c0:a9:9e:d2:43:2c:3f:5b:79.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
执行到这里就停了,按理说应该继续输入密码推送成功的才对