1,日期對象轉時間戳current_day
2,計算增量的時間戳,即循環每步的增量one_day
3,循環體計算,日期變量加增量後重新賦值自己
4,時間戳轉回日期格式後輸出
current_day=2015-07-17
end_day=2014-01-01
#步驟1
timestamp_current=`date -d "$current_day" +%s`
timestamp_end=`date -d "$end_day" +%s`
#步驟2
one_day=$((24*60*60))
while [ $timestamp_current -ge $timestamp_end ]
do
echo $timestamp_current
#步驟4
date -d @$timestamp_current +%Y-%m-%d
sh /opt/uv_report/hive_2_hdfs_ad_day.sh /user/wizad/uv_report/uv_day/ $timestamp_current
exitCode=$?
if [ $exitCode -ne 0 ];then
echo "[ERROR] uv_day for $timestamp_current"
exit $exitCode
fi
sh /usr/local/datahub/DataHub.sh /opt/uv_report/uv_day_2_mysql.xml -p /opt/uv_report/uv_day_2_mysql_params -d job.business.date=2015-07-30
if [ $exitCode -ne 0 ];then
echo "[ERROR] insert into mysql table for $timestamp_current"
exit $exitCode
fi
#步驟3
timestamp_current=$(($timestamp_current-$one_day))
done