本文共 551 字,大约阅读时间需要 1 分钟。
#!/usr/bin/bash
###批量上传密钥password=12345qwert
for i in {2..254} ######批量获取ip地址do{ ip=192.28.1.$iping -c1 -W1 $ip &>/dev/null ####记录成功的ipif [ $? = 0 ];thenecho "$ip">>ip.txt/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}&donewaitecho "fininsh.."转载于:https://blog.51cto.com/5776643/2371227