推送公钥

#!/usr/bin/env bash
>ip.txt

rpm -q expect &>/dev/null
if [ $? -ne 0 ];then
yum -y install expect
fi

if [ ! -f /root/.ssh/id_rsa.pub ];then
ssh-kengen -P "" -f /root/.ssh/id_rsa
fi

for i in `cat slave.txt`
do
{
ping -c $i &>/dev/null
if [ $? -eq 0 ];then
echo "$i" >> ip.txt
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh-copy-id $i
expect {
"yex/no" { send "yex\r"; exp_continue}
"password:" { send "123456\r" }
}
expect eof
EOF
fi
}&
done
wait
echo "finnish...."

posted @ 2018-03-19 14:38  Tom-Zhao  阅读(118)  评论(0编辑  收藏  举报