Tag Archives: EOD

OSX bash & expect

By jnojr

I have a script that must perform a ‘sudo’ operation on each of a number of hosts. I’m trying to get expect working so I only have to enter it once, and have run into a couple of issues.

First, several examples suggest to use:

Code:

/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:

Code:

/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

Scrolling through text while interacting with program prompts

By nanlee

Hi all,

I am trying write a shell script to automate the installation of a program, but during the process of the installation, the installation program requires the user to scroll through 10 pages of a license agreement. Since this is coming from stdout and is not a prompt, I am unable to send the space keys to scroll through all of the text to get to the next prompt. Right now I have something like this:

sh ./(installation program) <<EOD
yes
(here I want to scroll through the license agreement to get to the next prompt)
yes
etc
EOD

Has anyone done anything like this? Any help would be much appreciated!

Source: FULL ARTICLE at The UNIX and Linux Forums