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

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

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 "


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页