VirtualView.sh
#!/usr/bin/sh
project_name="cy1_odps"
conf="/root/odpscmd/conf/odps_config_cy.ini"
odpscmd="/root/odpscmd/bin/odpscmd"
id=$(date +%s)
echo -e "==================START!====================\n\n"
tables=$($odpscmd --config=$conf -e "use $project_name;show tables"|awk -F: '{print $NF}')
for table in $tables
do
res=$($odpscmd --config=$conf -e "use $project_name;desc ${table}"|grep "VirtualView : YES"|wc -l)
if [ $res -eq 1 ]
then
echo $table "is a VirtualView!"
echo $table >> ${project_name}_view.list
fi
done
for view in $(cat ./${project_name}_view.list)
do
res=$($odpscmd --config=$conf -e "use $project_name;export table ${view};")
echo "$res"|grep create >>${project_name}_create.sql
echo -e "对象 $table 创建语句为:\c" && echo "$res"|grep create
done