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

来源:互联网 发布:奇迹服务端源码 编辑:程序博客网 时间:2024/05/17 02:43

加群:397706991,共同学习

具体Shell代码下载:http://download.csdn.net/detail/luo849278597/9490920

conf/flow.sh

<?xml version="1.0" encoding="UTF-8"?><root><!-- 配置调度模块 --><task type="import.sh">../conf/import.xml</task><!-- 数据导入模块 --><task type="hive.sh">../conf/hive.xml</task><!-- 数据分析模块 --><task type="export.sh">../conf/export.xml</task><!-- 数据导出模块 --></root>

bin/flow.sh
#! /bin/bash###########################################sed命令是Shell编程中用于处理字符串,过滤出所需字符串的命令  #tr -d '\r' 用于删除每行中的换行符###########################################get the environmentif [ -f ~/.bashrc ];then . ~/.bashrcfi#file exitif [ -z $1 ];thenecho 'USAGE:COMMAND FILENAME'exit 0fibin=`dirname "$0"`bin=`cd "$bin"; pwd`declare -i j=0declare -a commandsdeclare -a filescontent=`sed -e 's/\s*\(.*\)\s*$/\1/g' -e 's/\s*\(=\)\s*/\1/g' -e '/^\(\s\)*$/d' -e '/^$/d' $1`while read linedo \if echo ${line}|grep -qE "^<task" ; thencommand=`echo ${line}|sed -n -e 's/<task type=\"//' -e 's/\">.*<\/task>//' -e 's/<!--.*-->//p'|tr -d '\r'`file=`echo ${line}|sed -n -e 's/<task type=\".*\">//' -e 's/<\/task>//' -e 's/<!--.*-->//p'|tr -d '\r'`if [ ${#file} -ne 0 ] ; thencommands[$j]="$command"files[$j]="$file"let j++fifidone \<<EOF$contentEOFflow='echo "flow.sh excute begin" && 'for((i=0;i<${#commands[*]};i++))do flow="${flow}${bin}/${commands[$i]} ${files[$i]} && "done flow="${flow}echo \"flow.sh excute finined!\""eval $flow
0 0
原创粉丝点击