Post a shell script for future reference.

Source: Internet
Author: User
Tags hdfs dfs

1#! /bin/Bash2 3icms_path=$ (CD $ (dirname$0);pwd)4deploy_path=$ (CD $ (dirname$ICMS _path);pwd)5jar_file= $DEPLOY _path'/dailydata-1.0-snapshot.jar'6ini_file= $DEPLOY _path'/cnedmp_etl.ini'7log_file= $DEPLOY _path'/shellrun.log'8coding='GB2312'9 Ten if[$#-ne1]; Then OneLogging INFO"ussage: $ <source file path>" AExit1 - fi -  the#Funtion forLog - functionlogging () { -logtime=$ (Date+"%y-%m-%d%T") -     Echo "$logTime $" + } - Source $INI _file +password= ' yarn jar $JAR _file com.hypers.etl.file. Specialfileprocess.blowfish ' Asrc_dir=$1 atLogging INFO"going to process all the source file under path: $SRC _dir" - CD $SRC _dir -partition=$ (Echo$SRC _dir |awk-f/'{print $ (NF-1)}') -Logging INFO"The partition is $partition" -filelist=$ (ls$dir) -Logging INFO"Would handle $filelist under Path $SRC _dir" inLogging INFO"-----------------------------" -  to  forFileNameinch$filelist +  Do -  theLogging INFO"---------------------------" *Logging INFO"handling file $filename ..." $ Panax NotoginsengPre_location= ' Mysql-h$hostname-u$username-p$password $DBNAME <<eof2>/dev/NULL|Tail-N +2 -SELECT pre_location from $CONFNAME where file_name='$filename'; the EOF ' +year=$ (Echo$partition |Cut-B1-4) Apre_location= $PRE _location/$year theLogging INFO"get pre file location $PRE _location for $filename" +  -Targ_location= ' Mysql-h$hostname-u$username-p$password $DBNAME <<eof2>/dev/NULL|Tail-N +2  $SELECT target_location from $CONFNAME where file_name='$filename'; $ EOF ' -targ_location= $TARG _location/$partition -Logging INFO"get target file location $TARG _location for $filename" the  -Targ_table_name= ' Mysql-h$hostname-u$username-p$password $DBNAME <<eof2>/dev/NULL|Tail-N +2 WuyiSELECT trg_table_name from $CONFNAME where file_name='$filename'; the EOF ' -Logging INFO"get target table name $TARG _table_name for $filename" Wu  -HDFs DFS-mkdir-P $PRE _location && logging INFO"Created $PRE _location succesfully" AboutHDFs DFS-mkdir-P $TARG _location && logging INFO"Created $TARG _location succesfully" $  -HDFs dfs-put $filename $PRE _location && logging INFO"Put $filename onto HDFs prelocation $PRE _location" -  -Yarn jar $JAR _file com.hypers.etl.file. Mr. Clidriver-i ${pre_location}'/'${filename}-o ${targ_location}-e ${coding}-D ${partition}-S',' A  +Logging INFO"ALTER TABLE $TARG _table_name to add partition" the#sudo suHdfs-c"beeline-u jdbc:hive2://${hostname}:10000/cnedmp-n hdfs-p $HIVE _server2_password-e"ALTER TABLE $TARG _table_name add Partition dt ='${partition}'Location'${targ_location}';" " -  $  Done

Post a shell script for future reference.

Related Article

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.