unix 下 shell 遍历指定范围内的日期
UNIX下遍历日期,date 没有 -d 的参数,所以需要自己处理。
下面使用时差的方法进行计算,遍历的日期是降序的
#!/usr/bin/ksh
. $HOME/.profile
timelag=
cycle=
begindate=$
enddate=$ Usage()
{
print "Usage: batch_miniestore.sh 开始日期 结束日期"
print " 注意:开始时间 >= 结束时间,使用递减方式遍历"
print " example:batch_miniestore.sh 20171208 20171203"
}
traverse_date()
{
if [ ${begindate} -lt ${enddate} ]; then
print "begindate is:"${begindate}
print "enddate is:"${enddate}
Usage
return
fi
#当前时间
today=`date +%Y%m%d`
print "today is:"${today} #计算当前时间和指定的起始时间的间隔数
flag=$((today-begindate))
print "flag:"${flag} #根据间隔数确定时差的取值
if [ flag -eq ]; then
timelag=
elif [ flag -eq ]; then
timelag=
else
timelag=$((+*(flag-)))
fi curdate=`TZ=aaa${timelag} date +%Y%m%d`
print "start date is:"$curdate #遍历时间:从起始时间依次递减进行遍历
while [ ${curdate} -gt ${enddate} ]
do
#根据时差得到起始的时间
curdate=`TZ=aaa${timelag} date +%Y%m%d`
print "curdate is:"$curdate
timelag=$((timelag+cycle))
done
}
traverse_date
unix 下 shell 遍历指定范围内的日期的更多相关文章
- Oracle 生成指定范围内随机日期
Oracle生成一个指定范围内的随机日期 /* 年1月1日)的整数偏移量来保存(即把日期保存为一个数字); * 因此可通过寻找‘指定日期’与‘关键日期’相对应的整数偏移量,再加一个指定范围内的随机整数 ...
- shell查找指定时间段内的文件
#!/bin/bash#20170905 输入参数格式echo "显示"$1"的备份文件"date_0=$1date_1=`expr $date_0 + 1`d ...
- Linux/Unix下Shell快捷键操作集合
本人收集整理了一些Bash或其他Shell中常用的快捷键,使用技巧以及Ubuntu中一些常用操作的快捷键,希望大家能从中受益,提高工作效率. 使用”!”从历史中执行命令 有时候,我们需要在 Bash ...
- Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件
脚本内容如下: #!/bin/bash function delete_file { days=$[$-] for i in `find $dir -type f -ctime +$days` do ...
- shell统计指定范围内的所有质数以及它们的和
#!bin/bash a= $) ;do n= $x);do ];then n=$[$n+] fi done ];then { echo -n -e "$x\t" sum=$[$s ...
- shell生成指定范围内的随机数
#!/bin/bash read -p "请输入起始数:" min read -p "请输入终止数:" max if [ $min -gt $max ] the ...
- random and password 在Linux下生成crypt加密密码的方法,shell 生成指定范围随机数与随机字符串
openssl rand -hex n (n is number of characters) LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head ...
- Window Linux下实现指定目录内文件变更的监控方法
转自:http://qbaok.blog.163.com/blog/static/10129265201112302014782/ 对于监控指定目录内文件变更,window 系统提供了两个未公开API ...
- OpenCV代码提取:遍历指定目录下指定文件的实现
前言 OpenCV 3.1之前的版本,在contrib目录下有提供遍历文件的函数,用起来比较方便.但是在最新的OpenCV 3.1版本给去除掉了.为了以后使用方便,这里将OpenCV 2.4.9中相关 ...
随机推荐
- pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据
原型: #include <pthread.h> void *pthread_getspecific(pthread_key_t key); int pthread_setspecific ...
- js 去除字符串两边的空格
js 去除字符串两边的空格 function trim(str){ //删除左右两端的空格 return str.replace(/(^\s*)|(\s*$)/g, "&q ...
- 洛谷 4245 【模板】任意模数NTT——三模数NTT / 拆系数FFT
题目:https://www.luogu.org/problemnew/show/P4245 三模数NTT: 大概是用3个模数分别做一遍,用中国剩余定理合并. 前两个合并起来变成一个 long lon ...
- 创建Task的多种方法
Gradle的Project从本质上说只是含有多个Task的容器,一个Task与Ant的Target相似,表示一个逻辑上的执行单元. 我们可以通过多种方式定义Task,所有的Task都存放在Proje ...
- What makes an inferred latch? how To avoid creating inferred latches? when do you know you need latches?
What makes an inferred latch?For combinatorial logic, the output of the circuit is a function of inp ...
- webrtc自带client的音频引擎创建代码走读
src\webrtc\examples\peerconnection\client\conductor.cc1.bool Conductor::InitializePeerConnection()1. ...
- linux上安装gitolite和windows上安装tortoisegit及msysgit
1 quick install+setup for experts If your Unix-fu and ssh-fu are good, just copy your ssh public key ...
- mysqldump全备份脚本mysqlallbackup.sh
库小,大概16G左右,每天增量很小,不到100M,所以用mysqldump每天全量备份,将备份结果信息发送到email通知DBA. mysqlallbackup.sh :MySQL DataBase ...
- MySQL 采用Xtrabackup对数据库进行全库备份
1,xtrabackup简介 关于数据库备份以及备份工具,参考:http://blog.itpub.net/26230597/viewspace-1460065/,这里来介绍xtrabackup已经如 ...
- HTTP:HTTP百科
ylbtech-HTTP:HTTP百科 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计 ...