当前位置: 代码迷 >> 综合 >> scp ssh输入用户名密码 执行命令
  详细解决方案

scp ssh输入用户名密码 执行命令

热度:19   发布时间:2023-12-16 23:53:26.0

执行拷贝到远程服务器命令,然后执行部分命令;

set user "root"
set host "127.0.0.1"
set loginpass "root"
set cmd_prompt "]#|~]?"expect -c "
spawn scp -r /usr/test/target/aaa-web/ ${
    user}@${
    host}:/usr/test/aaa-web/webapps
expect {
    \"*assword\" {
    set timeout 300; send \"${
    loginpass }\r\";}\"yes/no\" {
    send \"yes\r\"; exp_continue;}}set timeout 1;ssh ${
    user}@${
    host} -p 22 ;expect {
    yes /no {
     send \" yes \r\"; exp_continue }*assword* {
     send \"${
    password}\r\" }} ;expect ${
    user}@${
    host}   {
    send \" ls -l \r\" }  ;expect ${
    user}@${
    host}  {
     send exit \r } ;expect eof "