Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.