欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

expect执行ssh-copy-id

程序员文章站 2022-07-12 16:14:55
...

#!/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