Alternatives to --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 install alternatives to --config java, without having to enter anything.

For example, when you enter "alternatives --config java", you are prompted to choose which version of java you need. Due to the way I installed java ("/ usr / sbin / alternatives --install / usr / bin / java java / location / of / jdk1.6 / bin / java 2"), parameter # "2" should always be the java i want to choose.

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

This is in a bash script.

thanks


Below is the code (now it works correctly):

#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 "; else echo "java jre installation failed"; fi 
+4
source share
4 answers

As a rule, you can serve any program that expects something on standard input, for example:

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

You can run the alternatives command also non-interactively. Instead of --config use the --set option to specify the path to the alternative directly.

 sudo alternatives --set java /location/of/jdk1.6/bin/java 
+16
source

This worked for me with Java 8:

  alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.8.0_60/bin/java 3 alternatives --config java <<< '3' 
+5
source

I did this using this script:

 tmp=`mktemp` echo 2 > $tmp alternatives --config java < $tmp rm -f $tmp 

< means that the contents of the $tmp file will be transferred to the input of the alternatives command.

Edit:. You can just use one channel, like the others:

echo 2 | sudo alternatives --config java

0
source

All Articles