数据仓库-shell脚本实现hive hdfs文件上传到目标ftp

总的来说就是一行一行的linux命令,组装起来就变成一个脚本了!

 

#!/bin/bash

cd /web/data/file/tmp

rm -rf table1_{Date_No}.txt
rm -rf table2_{Date_No}.txt
rm -rf table3_{Date_No}.txt
rm -rf table4_{Date_No}.txt



#导出hdfs上面的文件到指定目录,date_no为批次
hadoop fs -getmerge hdfs://SH1/user/hive/warehouse/database.db/table1/date_no={Date_No}/ /web/data/file/tmp/table1_{Date_No}.txt
hadoop fs -getmerge hdfs://SH1/user/hive/warehouse/database.db/table2/date_no={Date_No}/ /web/data/file/tmp/table2_{Date_No}.txt
hadoop fs -getmerge hdfs://SH1/user/hive/warehouse/database.db/table3/date_no={Date_No}/ /web/data/file/tmp/table3_{Date_No}.txt
hadoop fs -getmerge hdfs://SH1/user/hive/warehouse/database.db/table4/date_no={Date_No}/ /web/data/file/tmp/table4_{Date_No}.txt


#以下代码为文件名操作,可忽略####################
function rand(){
  min=$1
  max=$(($2-$min+1))
  num=$(($RANDOM+1000000000)) #增加一个10位的数再求余
  echo $(($num%$max+$min))
}

#生成三位随机数
rnd=$(rand 100 999)
#生成两位随机数
rnd2=$(rand 10 99)
#echo $rnd
  
mv table1_{Date_No}.txt "s_DD_BAS_21048_{Date_No}_"$rnd2"_"$rnd.dat

mv table2_{Date_No}.txt "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat

mv table3_{Date_No}.txt "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat

mv table4_{Date_No}.txt "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat

#获取文件行数和大小(字节)生成校验文件
line=$(cat "s_DD_BAS_21048_{Date_No}_"$rnd2"_"$rnd.dat |wc -l);
size=$(cat "s_DD_BAS_21048_{Date_No}_"$rnd2"_"$rnd.dat |wc -c);
echo "s_DD_BAS_21048_{Date_No}_"$rnd2"_"$rnd".dat|"$line"|"$size > "s_DD_BAS_21048_{Date_No}_"$rnd2.verf

line=$(cat "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -l);
size=$(cat "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -c);
echo "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd".dat|"$line"|"$size > "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2.verf

line=$(cat "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -l);
size=$(cat "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -c);
echo "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd".dat|"$line"|"$size > "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2.verf

line=$(cat "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -l);
size=$(cat "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat |wc -c);
echo "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd".dat|"$line"|"$size > "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2.verf

gzip "s_DD_BAS_21048_{Date_No}_"$rnd2"_"$rnd.dat
gzip "i_DDcontinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat
gzip "i_DDchannelinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat
gzip "i_DDstbinfo_BAS_02172_{Date_No}_"$rnd2"_"$rnd.dat

#以上代码为文件名操作,可忽略####################


rm -rf ./tempjf
mkdir ./tempjf
#split -100000 dwd_itv_cdn_mbh_d_{Date_No}.txt stats_pkg_mbh_iptv_
mv *.* ./tempjf/
cd ./tempjf

# index=0
# stats_pkg_mbh_iptv_20191013.txt
# for i in `ls | grep stats_pkg_mbh_iptv_`
# do
	# index=`expr $index + 1`;
	# if [ "$index" -eq "1" ];then 
		# filename=stats_pkg_mbh_iptv_{Date_No}.txt
	# else 
		# filename=stats_pkg_mbh_iptv_{Date_No}_$index.txt
	# fi
	# echo $filename
	# mv $i $filename
	#tar -zcvf $filename".tar.gz" $filename".txt"
# done

#这里上传文件
ftp -n<<! 
open 11.111.11.111
user ftp_account pwd 
binary
prompt 
cd /xx
mkdir {Date_No}
cd {Date_No}
mdel *.*
mput s_DD_BAS_21048_*

cd ../../xxx
mkdir {Date_No}
cd {Date_No}
mdel *.*
mput i_DDcontinfo_BAS_02172_*

cd ../../xxxx
mkdir {Date_No}
cd {Date_No}
mdel *.*
mput i_DDchannelinfo_BAS_02172_*

cd ../../xxxxx
mkdir {Date_No}
cd {Date_No}
mdel *.*
mput i_DDstbinfo_BAS_02172_*
close 
bye 
!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值