方法1
#!/usr/bin/env bash
date1="$1"
date2="$2"
echo "date1: $date1"
echo "date2: $date2"
tempdate=`date -d "-0 day $date1" +%F`
enddate=`date -d "-0 day $date2" +%F`
tempdateSec=`date -d "-0 day $date1" +%s`
enddateSec=`date -d "-0 day $date2" +%s`
echo "####################################"
echo 'tempdate: '$tempdate
echo 'enddate: '$enddate
for i in `seq 1 300`;
do
if [[ $tempdateSec -lt $enddateSec ]]; then
break
fi
echo $tempdate
python pc_jibzhuanti_url.py $tempdate
tempdate=`date -d "-$i day $date1" +%F`
tempdateSec=`date -d "-$i day $date1" +%s`
done
这是一个倒序输出时间的脚本,需要输入两个时间参数,一个是开始时间,一个是结束时间,如输入:
./pc_jibzhuanti_url_run.sh 2014-06-30 2014-06-01
输出的结果是:
date1: 2014-06-30
date2: 2014-06-01
####################################
tempdate: 2014-06-30
enddate: 2014-06-01
2014-06-30
2014-06-29
2014-06-28
2014-06-27
2014-06-26
2014-06-25
2014-06-24
2014-06-23
2014-06-22
2014-06-21
2014-06-20
2014-06-19
2014-06-18
2014-06-17
2014-06-16
2014-06-15
2014-06-14
2014-06-13
2014-06-12
2014-06-11
2014-06-10
2014-06-09
2014-06-08
2014-06-07
2014-06-06
2014-06-05
2014-06-04
2014-06-03
2014-06-02
2014-06-01
方法2
#!/bin/sh
datebeg=20120412
beg_s=`date -d "$datebeg" +%s`
for ((DAY=0;DAY<=31;DAY++));
do
DAY1=`date -d @$beg_s +"%Y-%m-%d"`
A1=`cat file.${DAY1}.txt|cmd1|cmd2|blablabla...`
B2=`cat file2.${DAY1}.txt|cmd1|cmd2|blablabla...`
echo "$DAY1"
echo "scale=2;$A1*100/$B2" | bc
beg_s=$((beg_s+86400))
done
方法3
STARTDAY=20141216
ENDDAY=20150204
sd=`date -d "$STARTDAY" +%s`
ed=`date -d "$ENDDAY" +%s`
DAYLEN=$(($(($ed-$sd))/86400))
#DAYLEN=0
echo $DAYLEN
sday=`date -d "$STARTDAY" +%Y-%m-%d`
syesday=`date -d "$sday + 1 day" +%Y-%m-%d`
echo $sday
echo $syesday
for((t=0;t<=$DAYLEN;t++));
do
itoday=`date +%Y%m%d -d "$sday +$t days"`
iyesday=`date +%Y%m%d -d "$syesday +$t days"`
echo $itoday
echo $iyesday
idayu=`date +%s -d "$itoday 00:00:00"`
indayu=`date +%s -d "$iyesday 00:00:00"`
echo $idayu;
echo $indayu;
addsql $idayu $indayu $itoday;
done