Automate SCP with multiple files with expect script

老子叫甜甜 提交于 2021-01-21 04:39:45

问题


So I have seen multiple posts on this and maybe I just haven't seen the right one.

I am using an expect script to scp multiple files from my locale to a remote. I dont want to set up keys for passwordless logins, because then the servers cant be blown away and stood up with out more work, yes I could automate the key creation, I would just rather not. So I want to be able to use the * but every time I use the * it tells me. The reason I want to use * instead of a full name is because the version number will keep changing and I dont want to go manually change the script every time.

/path/{Install.sh,programWithVerionAfter*\}: No such file or directory

Killed by signal 1. 

I am hoping that this is an easy fix or workaround. All I would like to do is scp these files so I can automate an install process with the click of a button. Thankyou in advance for any help

#!/usr/bin/expect -f

spawn scp /path/\{Install.sh,programWithVerionAfter*\} "root@IP:/tmp/.
expect {
   -re ".*es.*o.*" {
   exp_send "yes\r"
   exp_continue
  }
  -re ".*sword.*" {
    exp_send "Password\r"
  }
}
interact

回答1:


I found what I wanted with much more googleing. Thankyou for your help, hope this helps others

http://www.linuxquestions.org/questions/linux-general-1/scp-with-wildcard-in-expect-834813/

#!/usr/bin/expect -f

spawn bash -c "scp /path/* root@IP:/tmp/"
expect {
  -re ".*es.*o.*" {
    exp_send "yes\r"
    exp_continue
  }
  -re ".*sword.*" {
    exp_send "Password\r"
  }
}
interact



回答2:


You can use curl to copy files from your local host to your remote host via sftp (which is the same as copying using scp for all intents and purposes), and specify the username and password in the command, like so:

curl -T /files/to/copy/*  -u username:password ftps://ftpshost.domain.tld/


来源:https://stackoverflow.com/questions/25791699/automate-scp-with-multiple-files-with-expect-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!