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

So I have an expect script like this that works:

#!/usr/bin/expect
spawn scp me@myserver.com:* .
expect {
password: {send "mypassword"; exp_continue}
}

Based on the man page for expect, I think I should be able to do this instead from the command line to accomplish the same thing

expect -c "spawn scp me@myserver.com:* ." -c "expect {password: {send \"mypassword\\r\"; exp_continue}}"

But this returns to the terminal

spawn scp me@myserver.com:* .
me@myserver.com's password: 

and then after a few seconds gives up without an error message and never does anything.

Note

Yes, I'm well aware that I should not do this with scp and should instead use keys.

share|improve this question
up vote 0 down vote accepted

I'm not certain, but I suspect the multiple -c arguments are the problem. You can use a here-doc to pass the script on stdin:

expect <<'END'
spawn scp me@myserver.com:* .
expect {
password: {send "mypassword"; exp_continue}
}
END

The single quotes around the first 'END' will quote the whole document.

share|improve this answer
    
i did essentially this, but used echo to pipe into expect instead – G Gordon Worley III May 17 '13 at 14:05

You must log in to answer this question.

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