expect executes 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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326658367&siteId=291194637