在两个日期间循环的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"
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"
相关文章推荐
- SHELL循环遍历两个日期作为参数执行命令
- 指定开始和结束日期循环的shell脚本
- 获取两个日期间隔时间的shell脚本代码
- SHELL循环遍历两个日期作为参数执行命令
- 用shell脚本,指定两个日期,计算相隔天数
- shell循环(两个日期比较,改变某个特定日期来改变当前比较值)
- shell 两个日期之间循环
- 获取两个日期间隔时间的shell脚本代码
- 在shell脚本中获取上个月最后一天的日期方法
- shell for循环、循环变量值付给其他shell脚本的方法
- Shell脚本笔记(八)循环
- Shell脚本运行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell推断hdfs文件文件夹是否存在
- shell脚本删除两个字符串之间的内容
- shell脚本一个时间循环
- 一个shell for循环与case结合的脚本(监控程序状态)
- 从九九乘法口决脚本,比较awk、bash/ksh和Perl的循环控制结构[附awk\shell\Perl脚本]
- shell 脚本中while 循环只执行一次的问题
- Shell脚本基础17-while循环读取文件内容
- shell 循环中实现展示进度百分比的脚本方法2
- python写的计算两个日期之间的天数的脚本