hive集羣中間(臨時)表定時清理shell腳本
#!/bin/sh
#hive集羣中間表定時清理腳本
databases="odb pdb"
#hive集羣中所有庫庫名
stime=`date +%s`
#記錄當前時間
for db in $databases
do
#遍歷所有庫
echo "===========================開始清理庫$db======================================="
hive -e "use $db;show tables like 'vra*res*tmp';" >/home/deployer/zcb/tmp/db_tmp.txt
#取出當前庫中中間表表名
echo "=========================該庫下有以下中間表===================================="
cat /home/deployer/zcb/tmp/db_tmp.txt
#輸出顯示當前庫中中間表表名
echo "=========================中間表展示完畢========================================"
for tb in `cat /home/deployer/zcb/tmp/db_tmp.txt`
do
hive -e "use $db;drop table if exists $tb"
#挨個表刪除
done
echo "===========================清理庫結束$db======================================="
done
etime=`date +%s`
s=`echo "scale=0; ($etime - $stime)%60" | bc`
m=`echo "scale=0; ($etime - $stime)/60%60" | bc`
h=`echo "scale=0; ($etime - $stime)/60/60" | bc`
echo "========================================腳本執行完畢========================================="