Posts

Showing posts from March, 2018

bash script to install java on Linux

Install JDK 7 or JDK 8 by Shell Script on Linux Create a file on root directory with name of jdk-install.sh and give execute permission. # touch /root/jdk-install.sh # chmod +x jdk-install.sh #sh jdk-install.sh  jdk-archive-file.tar.gz ###################### #!/bin/bash ORACLE_DOWNLOAD_LINK=http://www.oracle.com/technetwork/java/javase/downloads/index.html ########## if [ "$#" = 0 ] then echo "Usage:$0 [options] jdk-archive-file.tar.gz" exit 1 fi JDK_ARCHIVE=$1 #Check if the script is running with root permissions if [ `id -u` -ne 0 ]; then    echo "The script must be run as root! (you can use sudo)"    exit 1 fi #   Is the file a valid archive? echo -n "Validating the archive file... " gunzip -t $JDK_ARCHIVE 2>> /dev/null if [ $? -ne 0  ]; then    echo "FAILED"    echo    echo "Provided file is not a valid .tar.gz archive: $JDK_ARCHIVE"    echo    echo "Be sure to download Linux .ta