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
上一篇: shell新增用户
下一篇: ajax交互struts返回json