Limok Palantaemon Limok Palantaemon - 1 month ago 15
Linux Question

Expect's "spawn" command does not support shell wildcards as in "spawn scp -r /home/user/dir1/* server:"

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:

#!/usr/bin/expect

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


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

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

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