By jnojr
First, several examples suggest to use:
/usr/bin/expect <<EOD
spawn ssh -t $host /usr/bin/sudo -v
expect "Password:"
send "$SUDOPASSn"
EOD
However, as soon as I enter the second ‘<', all of the quoting gets screwed up, and my script will terminate with an unexpected end of file. This is really strange, as I use the same mechanism with cat to write out files in other scripts.
Other examples suggest:
/usr/bin/expect -c "
spawn ssh -t $host /usr/bin/sudo -v
expect "Password:"
send "$SUDOPASSn"
"
Doing it this way (and adding -d to expect), I get errors about no tty and a repeat of my password with an ‘n’ appended to the end, so it isn’t sending a newline (I’ve tried ‘r’ as well), but instead appears to be escaping the ‘n’
Since most of the examples I’m finding are from Linux, I expect (ha, ha, pun not intended!) that they’re using a GNU expect, and I’m using a BSD expect. I am reading through the man page, but the word “spawn” appears so many times, it could be quite a while before I stumble across the correct instance.
I’ve been monkeying around with different quoting and can get some slightly different results, but I just don’t know exactly what expect is expecting to see 🙂
…read more
Source: FULL ARTICLE at The UNIX and Linux Forums