Bash Script Programming 11 JDK automatic deployment

Source: Internet
Author: User

Now we will demonstrate how to use Bash scripts to automatically deploy JDK.

Environment: ubuntu12.04 amd 64 desktop or server, which must be BASH Shell

Copy the directory Java to the target machine and run the install. Sh script with the root permission.

Take a look at the directory structure:

 
. ── Check. Sh ├ ── install. Sh ├ ── jdk1.6.0 _ 35 ── readme ── tool. Sh

Install. sh. This script will first call check. the function in the sh script checks whether JDK is installed and whether the version number is 1.6.0 _ 35. if no installation is available or the version number is different, install it.

The JDK 1.6.0 _ 35 directory is the Linux 64-bit JDK package of oralce after decompression.

Tool. Sh provides some basic functions for copying directories and creating soft links.

First check the install. Sh script:

#! /Bin/bash source check. shsource tool. shhasjavar =$? Src_jdk_files =. /jdk1.6.0 _ records =/usr/jdk1.6.0 _ 35if [$ R-EQ 1] Then ECHO "Java was installed" else echo "Java was not installed" copyfolder $ src_jdk_files $ export CreateLink $ dst_jdk_files/usr/jdk1.6 CreateLink '/usr/jdk1.6/bin/Java ''/etc/alternatives/Java 'createlink/etc/alternatives/Java/usr/bin/javafi

Check. Sh script again

 
#! /Bin/bash # Check Java is available in this sessionfunction hasjava {v = 'java-Version 2> & 1 'echo 'Check Java platform... 'pos = 'expr match "$ v" 'java version \ "1.6.0 _ 35 \" ''if [$ pos-GT 0] thenreturn 1 elsereturn 0 fi}

Finally, let's look at the tool. Sh script.

#! /Bin/bashfunction copyfolder {if [-d "$2"] thenecho "$2 folder exists already, stop copying. "elseecho" $2 folder doesn't exists, Start copying... "CP-r $1 $2 fi} # create a link ($2) to file ($1) function CreateLink {if [-F "$2"] thenecho "$2 link exists already, removing it... "RM $2 elseecho" $2 link doesn't exists, creating it... "fi echo" creating link: $2 to $1 "ln-S $1 $2}

With this, it will be much easier to work in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.