Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 '11 at 9:08
up vote 0 down vote accepted

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"
share|improve this answer

You must log in to answer this question.

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