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/bashread-p & amp; #39; Pleaseinputthedirectoryofhadoop, ex:/usr/hadoop: & amp; #39; hadoop_dirif [-d $ hadoop_dir]; thenecho... 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 2 3 4 5 6 7 8 Fs. default. name 9 Hdfs: // ip: port 10 11 12 Hadoop. tmp. dir 13 Tmp_dir 14 15 3. pay attention to other syntaxes: if []; then else fi while [] do... done I = 0 let I ++
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.