Installing java on linux using ssh
Question
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
Solution 2
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
OTHER TIPS
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.