Limok Palantaemon Limok Palantaemon - 11 months ago 55
Linux Question

When using expect to automate copying files through ssh, I can't copy only the contents of a directory

I am trying to make a bash script to automate the following so that I don't have to re-enter my ssh key each time (will explain why later):

scp -r /home/user/dir1/* cluster_server:

i.e I want to only copy the contents of dir1 directly into the home folder of the cluster_server. This works when I type it directly into command line. However, I tried to automate this with expect like so:


spawn scp -r /home/user/dir1/* cluster_server:
expect "id_rsa':"
send "$PASSWORD\r"

And I come up with a problem. The
doesn't work anymore. I can only do

spawn scp -r /home/user/dir1/ cluster_server:

Which makes a new directory. I know this is a trivial problem, but I'd like to figure out why this isn't working.

Also, it seems like in all the questions about using expect to automate ssh stuff, everyone answers that you should use ssh keys so you don't need a password. So before anyone suggests that, unfortunately I can't do that since I messed up my ssh keys when I tried to set up a new rsa id. I had to disable the auto gnome-keyring since I was getting this bug: How to remove a ssh key?

Answer Source

Expect does not understand shell's glob patterns. Try like this:

spawn bash -c "scp -r /home/user/dir1/* cluster_server:"