Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate SCP with multiple files with expect script

Tags:

linux

scp

expect

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
like image 275
Matt Avatar asked Sep 11 '14 15:09

Matt


People also ask

What is SCP in bash?

In Unix, you can use SCP (the scp command) to securely copy files and directories between remote hosts without starting an FTP session or logging into the remote systems explicitly. The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication.


1 Answers

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
like image 168
Matt Avatar answered Sep 28 '22 09:09

Matt