shell 判断月末日期
有一个需求,根据输入的时间段,在这个时间段中的是月末的日期执行脚本
解决如下:
#!/bin/bash
if [ -z $1 ]
then
echo "请输入年月日8位开始日期"
exit $E_MISSING_POS_PARAM
fi
if [ -z $2 ]
then
echo "请输入年月日8位结束日期"
exit $E_MISSING_POS_PARAM
fi
if [ $1 -gt $2 ]
then
echo "后面的日期需大于前面的日期"
exit $E_MISSING_POS_PARAM
fi
datebeg=$1
dateend=$2
set -e
beg_s=` date -d "$datebeg" +%s`
end_s=` date -d "$dateend" +%s`
while((end_s>=beg_s))
do
incdate=`date -d @$beg_s +%Y%m%d`
y=`date -d ''$incdate' 0 days' +%Y`
m=`date -d ''$incdate' 0 days' +%m`
d=`date -d ''$incdate' 0 days' +%d`
if [ $(date -d ''$incdate' 0 days' +%d) -eq $(cal $m $y |xargs|awk '{print $NF}') ]
then
echo "是月底,执行该天:$incdate"
#请属于需要执行的命令
else
echo "不是月底,跳过该天:$incdate"
fi
((beg_s+=86400))
done
运行脚本:
[root@master]# sh lastday.sh 20190620 20190801
不是月底,跳过该天:20190620
不是月底,跳过该天:20190621
不是月底,跳过该天:20190622
不是月底,跳过该天:20190623
不是月底,跳过该天:20190624
不是月底,跳过该天:20190625
不是月底,跳过该天:20190626
不是月底,跳过该天:20190627
不是月底,跳过该天:20190628
不是月底,跳过该天:20190629
是月底,执行该天:20190630
不是月底,跳过该天:20190701
不是月底,跳过该天:20190702
不是月底,跳过该天:20190703
不是月底,跳过该天:20190704
不是月底,跳过该天:20190705
不是月底,跳过该天:20190706
不是月底,跳过该天:20190707
不是月底,跳过该天:20190708
不是月底,跳过该天:20190709
不是月底,跳过该天:20190710
不是月底,跳过该天:20190711
不是月底,跳过该天:20190712
不是月底,跳过该天:20190713
不是月底,跳过该天:20190714
不是月底,跳过该天:20190715
不是月底,跳过该天:20190716
不是月底,跳过该天:20190717
不是月底,跳过该天:20190718
不是月底,跳过该天:20190719
不是月底,跳过该天:20190720
不是月底,跳过该天:20190721
不是月底,跳过该天:20190722
不是月底,跳过该天:20190723
不是月底,跳过该天:20190724
不是月底,跳过该天:20190725
不是月底,跳过该天:20190726
不是月底,跳过该天:20190727
不是月底,跳过该天:20190728
不是月底,跳过该天:20190729
不是月底,跳过该天:20190730
是月底,执行该天:20190731
不是月底,跳过该天:20190801
注释:只需要在输入你需要执行的命令即可。
shell 判断月末日期的更多相关文章
- shell判断文件是否存在
转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...
- linux中用shell获取时间,日期
linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...
- Linux shell判断文件和文件夹是否存在
shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...
- shell 判断字符串是否为数字
本篇文章主要介绍了"shell 判断字符串是否为数字",主要涉及到shell 判断字符串是否为数字方面的内容,对于shell 判断字符串是否为数字感兴趣的同学可以参考一下. #!/ ...
- shell判断条件是否存在
1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var ...
- shell 判断文件、目录是否存在
shell判断文件是否存在 1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...
- Javascript Date 判断输入日期是否正确
JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date ...
- Shell 判断文件或文件夹是否存在
#shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...
- [转] Linux shell判断文件和文件夹是否存在
shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...
随机推荐
- JAXB序列化对象与反序列化XML
1.什么是JAXB JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术. 该过程中,JAXB也提供 ...
- xdebug调试的原理
转自 https://segmentfault.com/a/1190000002528341 使用PhpStorm+xdebug单步调试程序可以快速帮助自己熟悉项目代码! 运行原理 在实际使用前,我们 ...
- iOS-上传头像的使用
static NSString *const uploadSuccess = @"更改头像成功"; @interface DMAccountInformationViewContr ...
- PHP中使用CURL实现GET、POST、PUT、DELETE请求
/** * @param $url * @param $data * @param string $method * @param string $type * @return bool|string ...
- JAVA数据结构和算法 2-数组
数组中使用的主要算法:插入.查找(线性查找-无序/二分查找-有序).删除 在JAVA中数组属于对象类型: 1.创建方法有3种: 或者 数组一旦创建,大小不可改变.数组大小可以通过length字段获得: ...
- SIFT学习笔记之二 特征提取
特征提取函数: int _sift_features( IplImage* img, struct feature** feat, int intvls, double sigma, double c ...
- C++.控制台_界面颜色
1.c++中system(_color )怎样用?-CSDN论坛.html(https://bbs.csdn.net/topics/390758320) 2. 2.1. 颜色属性由两个十六进制数字指定 ...
- 通过IP得到IP所在地省市
/// <summary> /// 通过IP得到IP所在地省市(Porschev) /// </summary> /// <param name="ip&quo ...
- JAVA连接Sql-Server教程
一.下载相应的版本的jar文件(官网:https://docs.microsoft.com/zh-cn/sql/connect/jdbc/system-requirements-for-the-jdb ...
- redis的事物操作