expect执行ssh-copy-id


#!/bin/bash
ip=$1
uname=$2
password=$3
filepath=/usr/$uname/.ssh/id_rsa.pub
if [ $uname = "root" ];then
filepath=/root/.ssh/id_rsa.pub
fi
echo "===========resrsa===================="
expect <<EOF
spawn ssh-copy-id -i $filepath $uname@$ip
expect {
"*yes/no"    {
send "yes\r";
exp_continue
}
"*password:" {
send "$password\r"
}
}
expect eof
EOF

猜你喜欢

转载自lyongq04.iteye.com/blog/2297254