用jsp做网站的代码,义乌做网站的公司,wordpress软件分享,手机h5制作软件哪个好数据安全管理#xff0c;本shell 实现对hive源表敏感字段进行md5加密#xff0c;然后写入新表#xff1b; read -p 交互输入#xff1a;要脱敏的hive表、分区,示例: test_db.table_name 20240331 生成更新hive分区表的hql: insert overwrite table xxx 备注#xff1a;仅供… 数据安全管理本shell 实现对hive源表敏感字段进行md5加密然后写入新表 read -p 交互输入要脱敏的hive表、分区,示例: test_db.table_name 20240331 生成更新hive分区表的hql: insert overwrite table xxx 备注仅供参考可对本shell代码做进一步修改调整满足自己的需求。 #!/bin/bash
# 2024.04.19
read -p 请按示例格式输入要脱敏的hive表、分区,示例: test_db.table_name 20240331 ### table etl_date#获取库名、表名,存入变量
dbnameecho $table |awk -F. {print $1}
tblecho $table |awk -F. {print $2}target_dbimport_db#首先判断目标表是否存在
hdfs dfs -test -e /user/hive/warehouse/${target_db}.db/$tbl
if [ $? -eq 0 ] ;thenecho ${target_db}.$tbl 目标库已经存在...,请确认表结构是否与源表一致else# 1、 在 ${target_db} like 建表
echo 1、 create table ${target_db}.$tbl like $table;
beeline -e create table ${target_db}.$tbl like $table;# 2、 把hive表所有字段 切出来 备用
beeline --showHeaderfalse --outputformattsv2 -e desc $table |awk {print $1} desc_field.out
echo desc $table .... beeline ok#############################################md5表字段加密开始#############################################
numcat desc_field.out |grep NULL |wc -l
if [ $num 1 ] ;then# tac desc_field.out |sed -n 6,$p |tac desc_field_final.outcat desc_field.out |sed /NULL/,$d desc_field_final.out
elsecat desc_field.out desc_field_final.out
fi# 需要脱敏的敏感字段手动添加维护
sensitive_fields(name phone iden tel)fieldscat desc_field_final.out
mcat desc_field_final.out |wc -l
flag0md5_fields
echo $md5_fields
# 嵌套循环拿 表字段 与 敏感字段 进行匹配表字段如果是敏感字段进行MD5 加密拼接 sql 字符串
for j in $fields
dobiaoji1# 1.匹配到进行md5加密拼接标记置为0跳出内循环2.没有匹配到继续下一轮内循环length${#sensitive_fields[*]}# length 控制内循环的次数for ((i0;i${length};i))doecho i$iif [ $j ${sensitive_fields[i]} ]thenmd5_fields${md5_fields},md5($j) as $jbiaoji0breakelsecontinuefidone# 内循环执行一轮结束对 biaoji 的值进行判断为1说明 表字段 非敏感字段进行拼接if [ $biaoji 1 ]thenmd5_fields${md5_fields},$jfiecho $md5_fields((flag))echo flag$flag# 外循环次数 等于 表字段数外循环完成拼接 md5_fields 完成if [ $flag -eq $m ]then# 删除 md5_fields 串里第一个逗号正确的 md5_fields 拼接完成md5_fieldsecho $md5_fields | sed s/,//echo $md5_fieldsfidone
#############################################md5表字段加密结束##########################################################分区###############
in_values$etl_date
echo in_values$in_values# in_values
# for i in 20240131,20240228,20240331
# do
# in_values$in_values,$j
# done
# # ,20240131,20240228,20240331
# in_valuesecho $in_values |sed s/,//
# # 20240131,20240228,20240331
# echo in_values$in_values
###############分区################ 3、对分区字段个数计数 如果是分区表取出分区字段
partition_field_num sed -n /#/,$p desc_field.out |grep ^[^#] |wc -l
echo partition_field_num$partition_field_numsqlinsert overwrite table $target_db.$tbl
echo 初始$sql# 4、生成更新分区数据的语句;分区字段个数不同生成不同的 insert overwrite table
if [ $partition_field_num -eq 2 ];thenpartition1$(echo sed -n /#/,$p desc_field.out |grep ^[^#] |awk {print $1})partition2$(echo sed -n /#/,$p desc_field.out |grep ^[^#] |awk {print $2})sql$sqlpartition($partition1,$partition2) select $md5_fields from $table where $partition1 in ($in_values);echo 拼接2个分区后$sqlelif [ $partition_field_num -eq 1 ];thenpartition1$(echo sed -n /#/,$p desc_field.out |grep ^[^#] |awk {print $1})sql$sqlpartition($partition1) select $md5_fields from $table where $partition1 in ($in_values);echo 拼接1个分区后$sqlelsesql$sqlselect $md5_fields from $table;echo 无分区$sqlfi# 5、生成 update_partitions.sql
cat -EOF update_partitions.sql
set hive.execution.enginetez;
set tez.queue.nameroot.default;
set hive.tez.java.opts-Xmx6144m;
set hive.tez.container.size8192;
set hive.exec.dynamic.partitiontrue;
set hive.exec.dynamic.partition.modenonstrict;
set hive.exec.dynamic.partitions.pernode1000;
EOF
echo $sql update_partitions.sqlfi