Example of the hadoop configuration file automatically configured by shell

Source: Internet
Author: User

Example of the hadoop configuration file automatically configured by shell [plain] #! /Bin/bash read-p 'Please input the directory of hadoop, ex:/usr/hadoop: 'hadoop_dir if [-d $ hadoop_dir]; then echo 'yes, this directory exist. 'else echo 'error, this directory not exist. 'Exit 1 fi if [-f $ hadoop_dir/conf/core-site.xml]; then echo "Now config the $ hadoop_dir/conf/core-site.xml file. "read-p 'Please input the ip value of fs. default. name, I. e. hdfs: // ip: port: 'IP I = 1 wh Ile [-z $ ip] do read-p 'Please input the ip value of fs. default. name, I. e. hdfs: // ip: port: 'IP let I ++ echo $ I if [$ I-gt 2]; then echo 'You have input three time, done, exit. 'Exit 1 fi done if [$ ip = '']; then echo 'the value of ip can not null, exit. 'Exit 1 fi read-p "Please input the port value of fs. default. name, I. e. hafs: // $ ip: port: "port if [$ port ='']; then echo 'the value Of port can not null, exit. 'Exit 1 fi read-p' Please input the dir value of hadoop. tmp. dir: 'hadoop_tmp_dir if [$ hadoop_tmp_dir = '']; then echo 'the value of hadoop. tmp. dir can not null, exit. 'Exit 1 else if [! -D $ hadoop_tmp_dir]; then echo 'the directory you have input is not exist, we will make it. 'mkdir-p $ hadoop_tmp_dir fi tmp_dir =$ (echo $ hadoop_tmp_dir | sed's: // :\\/: G ') sed-I "s/ip/$ ip/g" $ hadoop_dir/conf/core-site.xml sed-I "s/port/$ port/g" $ hadoop_dir/conf/core-site.xml sed- I "s/tmp_dir/$ tmp_dir/g" $ hadoop_dir/conf/core-site.xml else echo "The file $ hadoop_dir/core-site.xml doen't exist." Exit 1 fi cat $ hadoop_dir/conf/core-site.xml echo 'config the core-site.xml success! 'Echo key analysis: 1. tmp_dir = $ (echo $ hadoop_tmp_dir | sed's:/: \/: G') The $ hadoop_tmp_dir we input is similar to/usr/hadoop/tmp, an error occurs if you write it directly in sed: sed-I "s/tmp_dir/$ hadoop_tmp_dir/g" $ hadoop_dir/conf/core-site.xml. Because it will be parsed into: sed-I "s/tmp_dir/usr/hadoop/tmp/g" $ hadoop_dir/conf/core-site.xml, apparently not satisfied, the solution is to convert the/usr/hadoop/tmp input to \/usr \/hadoop \/tmp, that is, add escape characters. Sed's:/: \/: G'. Then, use $ () to assign the value to the variable. 2. sed-I "s/ip/$ ip/g" $ hadoop_dir/conf/core-site.xml here is the so-called replacement of strings in the file, the example file is: [plain] root @ ubuntu:/home/houqd/hadoop/conf # cat-n core-site.xml 1 <? Xml version = "1.0"?> 2 <? Xml-stylesheet type = "text/xsl" href = "configuration. xsl"?> 3 4 <! -- Put site-specific property overrides in this file. --> 5 6 <configuration> 7 <property> 8 <name> fs. default. name </name> 9 <value> hdfs: // ip: port </value> 10 </property> 11 <property> 12 <name> hadoop. tmp. dir </name> 13 <value> tmp_dir </value> 14 </property> 15 </configuration> 3. note other Syntax: if []; then else fi while [] do .. done I = 0 let I ++

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.