Automate SCP with multiple files with expect script

Matt picture Matt · Sep 11, 2014 · Viewed 20.7k times · Source

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

Answer

Matt picture Matt · Sep 11, 2014

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