prolink007 prolink007 - 1 year ago 66
Linux Question

alternatives --config java bash script

I am writing a script that installs java on a remote machine. After i run the .bin file for the JRE, how can i set the alternatives --config java without the user having to input anything.

For instance, when you type in "alternatives --config java" you are prompted to select which java version you would like. Due to the way i installed java ("/usr/sbin/alternatives --install /usr/bin/java java /location/of/jdk1.6/bin/java 2") the #"2" option should always be the java that i want selected.

So, using an ssh command execution, how can i select the second option for java alternatives without the user having to choose the option. I want it fully automated.

This is in a bash script.


Below is the code (working correctly now):

#install the jre
sshRetValue=`ssh -p "22" -i $HOME/sshids/idrsa-1.old ${1} " /home/geiser/jms_adapter/jre-6u25-linux-i586.bin "`;
sshRetValue=`echo $?`;
if [ "$sshRetValue" -eq 0 ];then
echo "java jre installed successfully";
#set the alternative and stuff if needed
ssh -p "22" -i $HOME/sshids/idrsa-1.old ${1} " /usr/sbin/alternatives --install /usr/bin/java java /root/jre1.6.0_25/bin/java 2 ";
echo 2 | ssh -p "35903" -i $HOME/sshids/idrsa-1.old ${1} " alternatives --config java ";
echo "java jre installation failed";

Answer Source

Generally, you can feed any program that expects something on the standard input like this:

echo -e "line 1\nline 2\nline 3" | program