填写project清单
[root@ecs /home/caoyu/odps/desc_table]$ cat projects_list
odps1_uat1
odps2_uat1
执行脚本sh desc_table.sh
#!/bin/sh
start_time=`date +%s` #定义脚本运行的开始时间
tmp_fifofile="/tmp/$$.fifo"
mkfifo $tmp_fifofile # 新建一个FIFO类型的文件
exec 6<>$tmp_fifofile # 将FD6指向FIFO类型
thread_num=10 # 定义最大线程数
#根据线程总数量设置令牌个数
#事实上就是在fd6中放置了$thread_num个回车符
for ((i=0;i<${thread_num};i++));do
echo
done >&6
pwd_dir=`pwd`
uat1_dir=$pwd_dir/uat1_project/
dst_dir=$pwd_dir/dst_project/
if [ ! -d "$uat1_dir" ];then
mkdir -p $uat1_dir
else
echo "$uat1_dir路径已存在"
fi
if [ ! -d "$dst_dir" ];then
mkdir -p $dst_dir
else
echo "$dst_dir路径已存在"
fi
if [ -f $uat1_dir/* ];then
rm -f /home/caoyu/odps/desc_table/uat1_project/*
echo "$uat1_dir路径下文件已删除"
else
echo "$uat1_dir路径下为空"
fi
if [ -f $dst_dir/* ];then
rm -f /home/caoyu/odps/desc_table/dst_project/*
echo "$dst_dir路径下文件已删除"
else
echo "$dst_dir路径下为空"
fi
#project="bdm_rsk_uat1"
src_odpscmd=/home/caoyu/odpscmd_uat1/bin/odpscmd
src_conf=/home/caoyu/odpscmd_uat1/conf/odps_config.ini
dst_odpscmd=/home/caoyu/odpscmd_dst/bin/odpscmd
dst_conf=/home/caoyu/odpscmd_dst/conf/odps_config.ini
function src_tb(){
src_tables=$($src_odpscmd --config=$src_conf -e "use $1;show tables"|awk -F: '{print $NF}')
for tb1 in $src_tables
do
read -u6
{
count=$($src_odpscmd --config=$src_conf -e "use $1;desc $tb1"|grep -i 'decimal '|wc -l)
if [ $count -ge 1 ]
then
echo $tb1 >> $uat1_dir/$1.txt
fi
echo >&6
} &
done
}
function dst_tb(){
dst_tables=$($dst_odpscmd --config=$dst_conf -e "use $1;show tables"|awk -F: '{print $NF}')
for tb2 in $dst_tables
do
read -u6
{
count=$($dst_odpscmd --config=$dst_conf -e "use $1;desc $tb2"|grep -i 'decimal '|wc -l)
if [ $count -ge 1 ]
then
echo $tb2 >> $dst_dir/$1.txt
fi
echo >&6
} &
done
}
src_tb
dst_tb
while read line
do
project=`echo $line|awk '{print $1}'`
src_tb $project
dst_tb $project
done < projects_list
wait # 要有wait,等待所有线程结束
stop_time=`date +%s` # 定义脚本运行的结束时间
echo "TIME:`expr $stop_time - $start_time`" # 输出脚本运行时间
exec 6>&- # 关闭FD6
echo "over" # 表示脚本运行结束