views:

478

answers:

3

Hi

I want to install java on many computers using ssh so I want to write a bash script that will do (roughly):

for c in computers
do    
   scp jre--.rpm $c
   ssh $c 'sudu -s; chmod a+x jre--.rpm ; ./jre--.rpm; echo "success!"'
done

The problem is that during the java installation I need to "read" the notice and type "yes" at the end. How do I do it? Is there an easier way than "expect"? And if not how to I fit it in the bash script?

thanks a lot

+1  A: 

See this post:

Need help: Automatically accept EULA with apt-get

rajax
I'm using red hat - only "yum install" and it installs the open java which is worthless
Guy
Apparently there is a file you can create which when present will skip the EULA acceptance - no idea what file - but it might help.
rajax
that sounds like just what I need - any clue on how to create it?
Guy
+2  A: 

First, record the necessary keystrokes to a file like this:

cat > keystrokes

Hit ctrl+C when you're done recording keystrokes. Check the file content. Some keys like TAB may not record properly but you can still edit the file with a text editor. Note that scrolling down on a console (e.g. when reading output from more) can typically be done with the space bar.

You can scp this file like you already do with the rpm. Next, pipe the content of the keystrokes file to the standard input of the installer:

cat keystrokes | ./someinstaller

edit: Sorry to hear it doesn't work. Maybe you can take a look at expect, which is a unix tool designed for this sort of thing. I think it is included in most gnu/linux distributions. If you are familiar with python you may prefer pexpect instead.

Wim Coenen
This almost works, but not quite. It seems the input is heard only after I manually press SPACEBAR.
Guy
tried it also - doesn't work
Guy
+1  A: 

expect is the way to go (thanks http://www.dnmouse.org/java.html):

   for c in computers
   do    
       scp jre--.rpm $c
       ssh -t $c 'sudo -s; yum -y install expect; sudo chmod a+x jre--.rpm'
       ssh -t $c '/usr/bin/expect -c \
       "set timeout -1; spawn ./jre-6u13-linux-x64-rpm.bin; sleep 1; send -- q\r; sleep 1; send -- yes\r; expect eof"
       echo "success!"'
   done
Guy