#!/usr/bin/bash
###批量上传密钥
V.1.0 by chenght 2019-03-29
password=12345qwert
for i in {2..254} ######批量获取ip地址
do
{
ip=192.28.1.$i
ping -c1 -W1 $ip &>/dev/null ####记录成功的ip
if [ $? = 0 ];then
echo "$ip">>ip.txt
EOF 交互内容容易出错,请注意
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub -p 10022 admin@$ip ##上传的密钥写全路径#
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$password\r" }
}
expect eof
EOF
fi
}&
done
wait
echo "fininsh.."
原文地址:https://blog.51cto.com/5776643/2371227
时间: 2024-10-30 11:02:44