shell date处理

xyang@xyang-Latitude-E5440:~$ cat test.sh 
#!/bin/bash

today=$(date +%F)

if [ -n "$1" ];then
   today=$1
fi

yesterday=$(date -d "${today} -1 day" +%F)
afterweek=$(date -d "${today} +7 day" +%F)
dt=$(date -d "${today} -1 day" +%Y%m%d)
beforeweek=$(date -d"${today} -7 day" +%F)

echo $today
echo $yesterday
echo $afterweek
echo $dt
echo $beforeweek
xyang@xyang-Latitude-E5440:~$ bash test.sh
2015-11-11
2015-11-10
2015-11-18
20151110
2015-11-04

日期循环
begin_date="2016-01-01"
final_date="2016-02-17"

comparator=`date -d"$final_date" +%s`
b_com=`date -d"$begin_date" +%s`

while [ $b_com -lt $comparator ];do
    end_date=`date -d"$begin_date+1day" +%F`
    execute "$begin_date" "$end_date"
    begin_date=`date -d"$begin_date+1day" +%F`
    b_com=`date -d"$begin_date" +%s`
done



#!/bin/bash
MYSQL="mysql -h192.168.243.27 -uroot -p488ff8a0-d690-11e4-8676-ab1b3be0671a -Db2c_push -N -e"

begin_date="2016-02-15"
final_date="2016-02-26"

comparator=`date -d"$final_date" +%s`
b_com=`date -d"$begin_date" +%s`

function aa(){
while [ $b_com -lt $comparator ];do
    end_date=`date -d"$begin_date+1day" +%F`
    #execute "$begin_date" "$end_date"
    out_date=`date -d"$begin_date" +%Y%m%d`
    for((i=1;i<=22;i++));do
        sql="insert into everyday_push_20160226_${i}(uid,pid,gid,vid) select uid,pid,gid,vid from everyday_push_${out_date}_$i"
        $MYSQL"$sql"
    done
    begin_date=`date -d"$begin_date+1day" +%F`
    b_com=`date -d"$begin_date" +%s`
done
}

function main(){
    for((i=1;i<=22;i++));do
        sql="select count(1) from everyday_push_20160226_${i}"
        echo $i:`$MYSQL"$sql"`
    done
}

main


转载于:https://my.oschina.net/u/2510197/blog/528896

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值