1, Date object turn timestamp current_day
2, calculates the incremental timestamp, which is the increment of the loop per step one_day
3, loop body calculation, date variable plus increment re-assign value
4, time stamp back to date format output
Current_day=2015-07-17
End_day=2014-01-01
#step 1
Timestamp_current=`date -d "$current_day" +%s`
Timestamp_end=`date -d "$end_day" +%s`
#Step 2
One_day=$((24*60*60))
While [ $timestamp_current -ge $timestamp_end ]
Do
Echo $timestamp_current
#Step 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
#Step 3
Timestamp_current=$(($timestamp_current-$one_day))
Done
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell Date Date Loop method: Date format to timestamp calculation, then time stamp back to date format