Linux下Shell编程实现基于Hadoop的ETL(导出篇)

来源:互联网 发布:网络存在劫持 编辑:程序博客网 时间:2024/05/17 02:54

加群:397706991,共同学习

conf/export.xml

Shell代码下载地址:http://download.csdn.net/detail/luo849278597/9490920

<?xml version="1.0" encoding="UTF-8"?><root><task type="export"><table>think_statistics</table></task></root>

bin/export.sh
#!/bin/bash###########################################该shell文件的执行是基于Hadoop以及Sqoop工具的,因此系统需要安装Hadoop以及Sqoop,#并且正确配置其环境变量#sed命令是Shell编程中用于处理字符串,过滤出所需字符串的命令  #tr -d '\r' 用于删除每行中的换行符###########################################get the environmentif [ -f ~/.bashrc ];#进入Bash Shell环境,用于以下命令的执行then . ~/.bashrcfi#file exitif [ -z $1 ];then #判断配置文件是否存在echo 'USAGE:COMMAND FILENAME'exit 0fi#获取配置文件目录的路径bin=`dirname "$0"`bin=`cd "$bin"; pwd`declare -a tablesXML_PNODE=taskXML_CNODE=tabledeclare -i i=0FLAG=0OUTFILE=`sed -e 's/\s*\(.*\)\s*$/\1/g' -e 's/\s*\(=\)\s*/\1/g' -e '/^\(\s\)*$/d' -e '/^$/d' -e 's/<!--.*-->//' $1`while read linedoif echo ${line}|grep -qE "^<$XML_PNODE type=\"export\">" ; thenFLAG=1continuefiif echo ${line}|grep -qE "</$XML_PNODE>" ; thenFLAG=0continuefiif [ ${FLAG} -eq 1 ] ; thentmp=`echo ${line}|sed -n -e 's/<table>//' -e 's/<\/table>//p'|tr -d '\r'`tables[$i]=$tmplet i++continuefidone<<EOF$OUTFILEEOFshellsql="echo -e \"\033[41:33m excute export.sh start export tables \033[0m\""for ((i=0;i<${#tables[*]};i++))doshellsql="${shellsql} && ${bin}/sqoop.sh export --connect jdbc:mysql://master:3306/db_cda --username root --password 123 --table ${tables[$i]} --export-dir /user/hive/warehouse/${tables[$i]}"doneshellsql="${shellsql} && echo -e \"\033[41:33m excute export.sh finished export tables \033[0m\""eval $shellsql
0 0
原创粉丝点击