您的位置:首页 > 运维架构 > Shell

在两个日期间循环的shell脚本

2009-10-09 20:47 253 查看
#! /bin/bash

if [ $# -ne 2 ]

then

echo "Usage:$0 StartDate EndDate"

exit 1;

fi

start_dt="$1"

end_dt="$2"

start_in_seconds=`date +"%s" -d "$start_dt"`

end_in_seconds=`date +"%s" -d "$end_dt"`

tmp_in_seconds="$start_in_seconds"

while [ "$tmp_in_seconds" -le "$end_in_seconds" ]

do

curr_dt=`date +"%Y-%m-%d" -d @"$tmp_in_seconds"`

echo $curr_dt

let tmp_in_seconds=tmp_in_seconds+60*60*24

done

========================================

另:

date -d "2009-10-10"

date -d "now"

date -d "yesterday"

date -d @969205800 (969205800为距1970.1.1 0时的秒数)

date -d "3 days ago"

date -d "3 months ago"

date -d "+2 days"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: