简体   繁体   English

使用expect脚本自动化SCP多个文件

[英]Automate SCP with multiple files with expect script

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. 我正在使用expect脚本将我的语言环境中的多个文件scp到远程。 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. 我想做的就是scp这些文件,这样我只需点击一下按钮就可以自动完成安装过程。 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

I found what I wanted with much more googleing. 我找到了更多google的东西。 Thankyou for your help, hope this helps others 谢谢你的帮助,希望这有助于他人

http://www.linuxquestions.org/questions/linux-general-1/scp-with-wildcard-in-expect-834813/ 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

您可以使用curl通过sftp将文件从本地主机复制到远程主机(这与使用scp进行所有意图和目的的复制相同),并在命令中指定用户名和密码,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM