Linux下Shellプログラミング実装HadoopベースETL(Sqoopパッケージ編)


conf/sqoop.xml


	
		jdbc:mysql://master:3306/db_cda
		root
		123
		
		
		
		
		
		
		
		
		
		1
		
		
		
		
		'\\\\N'
		'\\\\N'
		
		
		
		true
		
		
		true
		true
	
	
	
		jdbc:mysql://master:3306/db_cda
		root
		123
		
		
		1
		
		
		
		
		'\\t'
		
		
		
		
		
		'\
'
bin/sqoop.sh
#!/bin/bash
#get the environment
if [ -f ~/.bashrc ];#  Bash Shell  ,        
then
 . ~/.bashrc

#         
bin=`dirname $0`
bin=`cd "$bin";pwd`
filename="$bin"/../conf/sqoop.xml
#if file not exsist,will exit;
fi
if [ -z $filename ];then
	echo 'USAGE:COMMAND FILENAME'
	exit 0
fi

#          
declare -i i=0
declare -i j=0
declare -a importKeys
declare -a importValues
declare -a exportKeys
declare -a exportValues

flag=0
#           、  、     
content=`sed -e 's/\s*\(.*\)\s*$/\1/g' -e 's/\s*\(=\)\s*/\1/g' -e '/^\(\s\)*$/d' -e '/^$/d' -e 's///' $filename`
#      XML       
while read line
do \
	if echo ${line}|grep -qE "^" ; then
		flag=1
		continue
	fi

	if echo ${line}|grep -qE "^" ; then
		flag=2
		continue
	fi

	if echo ${line}|grep -qE "" ; then
		flag=0
		continue
	fi

	if [ ${flag} -ne 0 ] ; then
		#     key 
		key=`echo ${line}|sed -n -e 's/.*//p'|tr -d '\r'`
		#     Value 
		value=`echo ${line}|sed -n -e 's///' -e 's///p'|tr -d '\r'`
		#  key   ,   
		if [ ${#key} -eq 0 ] ; then
			continue
		fi
		#      , key value            
		if [ ${flag} -eq 1 ] ; then
			importKeys[$i]=$key
			importValues[$i]=$value
			let i++
		elif [ ${flag} -eq 2 ] ; then
			exportKeys[$j]=$key
			exportValues[$j]=$value
			let j++
		fi
	fi
done \
<

具体的なShellコードのダウンロード:http://download.csdn.net/detail/luo849278597/9490920
加群:397706991,共同学習