1.按天倒序遍歷天
#!/bin/bash
firstDay=`date -d "-9 day" +%Y%m%d`
endDay=`date -d " -7 day" +%Y%m%d`
#遍歷下個月的每一天
source /opt/huawei/Bigdata/hiveClient/bigdata_env
while (( $firstDay <= $endDay ))
do
beeline -e "drop table dw.dw_doc_department_$firstDay "
firstDay=`date -d "+1 day $firstDay" +%Y%m%d`
done
2.按小時遍歷日期
#!/bin/bash
#以小時循環
#sh x.sh 2017010101 2017010301
stime=`date -d "-72 hours" +%Y%m%d%H`
etime=`date -d "-48 hours" +%Y%m%d%H`
source /opt/huawei/Bigdata/hiveClient/bigdata_env
while :
do
echo $stime
beeline -e "drop table ods.ods_order_info_dd_${stime}"
beeline -e "drop table ods.ods_user_info_dd_${stime} "
stime=$(date -d "${stime:0:8} ${stime:8:2} 1hour" +%Y%m%d%H)
if [[ $stime -gt $etime ]]
then
break
fi
done