shell中根据步长并发跑指定一段时间内的任务

#!/bin/bash

start_date='20160907'
end_date='20160705'
step=5

current_date=`date +%Y%m%d`
current_ts=`date +%s -d "$current_date"`

start_ts=`date +%s -d "$start_date"`
end_ts=`date +%s -d "$end_date"`
ibegin=`expr \( $current_ts - $start_ts \) \/ 86400`

sbegin=$ibegin
ebegin=`expr $ibegin + $step`

function task() {
startDate=$1
endDate=$2
startTs=`date +%s -d "$startDate"`
endTs=`date +%s -d "$endDate"`
begin=`expr \( $current_ts - $startTs \) \/ 86400`

while [ 1 ]
do
if [ $str -eq $endDate ];then
break
fi

{
//do task
}&
begin=`expr $begin + 1`
done
wait
}

while [ 1 ]
do
sdate=`date '+%Y%m%d' --date="-${sbegin} day"`
edate=`date '+%Y%m%d' --date="-${ebegin} day"`

if [ $edate -le $end_date ];then
edate=$end_date
fi

task $sdate $edate

if [ $edate -le $end_date ];then
break;
fi
sbegin=`expr $ebegin + 1`
ebegin=`expr $ebegin + $step`

done