#!/bin/bash
#
dir=/root/.ssh
scrfile=$dir/id_rsa
pubfile=$dir/id_rsa.pub
login_password='abcdefg'
localip=172.16.0.11
rpm -q expect &> /dev/null || yum install expect -y &> /dev/null
[ -d $dir ] || mkdir $dir
if [ ! -f $scrfile -o ! -f $pubfile ];then
ssh-keygen -f $scrfile -P "" &> /dev/null
expect <<-EOF
spawn ssh-copy-id -i $pubfile $localip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$login_password\n" }
}
expect eof
EOF
fi
while read ipaddr;do
expect <<-EOF
set timeout 10
spawn scp -pr $dir $ipaddr:/root/
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$login_password\n" }
}
expect eof
EOF
done < /root/ipaddr.txt
网友评论