加群:397706991,共同学习
conf/export.xml
Shell代码下载地址:http://download.youkuaiyun.com/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 environment
if [ -f ~/.bashrc ];#进入Bash Shell环境,用于以下命令的执行
then
. ~/.bashrc
fi
#file exit
if [ -z $1 ];then #判断配置文件是否存在
echo 'USAGE:COMMAND FILENAME'
exit 0
fi
#获取配置文件目录的路径
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
declare -a tables
XML_PNODE=task
XML_CNODE=table
declare -i i=0
FLAG=0
OUTFILE=`sed -e 's/\s*\(.*\)\s*$/\1/g' -e 's/\s*\(=\)\s*/\1/g' -e '/^\(\s\)*$/d' -e '/^$/d' -e 's/<!--.*-->//' $1`
while read line
do
if echo ${line}|grep -qE "^<$XML_PNODE type=\"export\">" ; then
FLAG=1
continue
fi
if echo ${line}|grep -qE "</$XML_PNODE>" ; then
FLAG=0
continue
fi
if [ ${FLAG} -eq 1 ] ; then
tmp=`echo ${line}|sed -n -e 's/<table>//' -e 's/<\/table>//p'|tr -d '\r'`
tables[$i]=$tmp
let i++
continue
fi
done<<EOF
$OUTFILE
EOF
shellsql="echo -e \"\033[41:33m excute export.sh start export tables \033[0m\""
for ((i=0;i<${#tables[*]};i++))
do
shellsql="${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]}"
done
shellsql="${shellsql} && echo -e \"\033[41:33m excute export.sh finished export tables \033[0m\""
eval $shellsql