#!/bin/bash
function_copy()
{
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$1
expect {
\"*yes/no*\" {send \"yes\r\";exp_continue}
\"*password*\" {send $2\r;exp_continue}}"
}
for Ip in `awk '{print $1}' /root/hosts.txt`
do
Passwd=`awk -v I=${Ip} '{if(I==$1) print $2}' /root/hosts.txt`
function_copy ${Ip} ${Passwd}
done
=========
host.txt文件中保存目标服务器的ip及本服务器的root密码,格式为
10.0.1.100 yourpassword
10.0.1.101 yourpassword