1

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?

Community
  • 1
  • 1
Marses
  • 1,464
  • 3
  • 23
  • 40

2 Answers2

1

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

spawn bash -c "scp -r /home/user/dir1/* cluster_server:"
pynexj
  • 19,215
  • 5
  • 38
  • 56
0

You do not need gnome-keyring to set up a new ssh key. You can follow this manual from Digital Ocean. It is really, really easier to do it once rather than mess with expect.

Anton Chikin
  • 1,746
  • 2
  • 17
  • 22