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