1

I'm trying to use expect to handle rsync over an ssh shell, but it gets stuck.

If I run my rsync command it works (simplified here): It prompts me for my password and copies files to the server:

rsync -e ssh -<other_params>

If I then enclose that in expect:

expect -d -c "spawn rsync -e ssh -<other_params>" -c "expect password:" -c "send mypass\r"

It does not execute properly, the program exists and no files are copied. Even the debug mode isn't giving many clues.

My best guess is that rsync is spawning the ssh process, and the ssh process is what needs to be interacted with, but send is picking up the rsync process id and sending the input there.

Any thoughts?

1
  • 1
    Can you set up your ssh for public-key/password-less login? Then you can dispense with expect. IF not, try spawning the subprocess with a pty rather than a pipe (if that's what it's doing).
    – Keith
    Jun 27, 2011 at 9:08

1 Answer 1

0

The answer to this issue was that I needed to add a wait command at the end of the expect script. As it is shown in the question, it was working, but it was sending the password and then immediately killing the process. Adding wait waits for the rsync process to complete.

Corrected version:

expect -d -c "spawn rsync -e ssh -<other_params>" -c "expect password:" -c "send mypass\r" -c "wait"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .