shell的date日期循环方法:日期格式转时间戳计算,再将时间戳转回日期格式
2015-07-31 17:12
871 查看
1,日期对象转时间戳current_day
2,计算增量的时间戳,即循环每步的增量one_day
3,循环体计算,日期变量加增量后重新赋值自己
4,时间戳转回日期格式后输出
2,计算增量的时间戳,即循环每步的增量one_day
3,循环体计算,日期变量加增量后重新赋值自己
4,时间戳转回日期格式后输出
current_day=2015-07-17 end_day=2014-01-01 #步骤1 timestamp_current=`date -d "$current_day" +%s` timestamp_end=`date -d "$end_day" +%s` #步骤2 one_day=$((24*60*60)) while [ $timestamp_current -ge $timestamp_end ] do echo $timestamp_current #步骤4 date -d @$timestamp_current +%Y-%m-%d sh /opt/uv_report/hive_2_hdfs_ad_day.sh /user/wizad/uv_report/uv_day/ $timestamp_current exitCode=$? if [ $exitCode -ne 0 ];then echo "[ERROR] uv_day for $timestamp_current" exit $exitCode fi sh /usr/local/datahub/DataHub.sh /opt/uv_report/uv_day_2_mysql.xml -p /opt/uv_report/uv_day_2_mysql_params -d job.business.date=2015-07-30 if [ $exitCode -ne 0 ];then echo "[ERROR] insert into mysql table for $timestamp_current" exit $exitCode fi #步骤3 timestamp_current=$(($timestamp_current-$one_day)) done
相关文章推荐
- shell的date日期循环方法:日期格式转时间戳计算,再将时间戳转回日期格式
- shell敏感词文件批量生成sql
- linux shell进行文件去重
- linux登陆之后显示bash-3.00$
- linux shell 之函数
- shell脚本
- linux shell的使用
- 创建powershell模块
- shell脚本中的if
- Crontab 让linux定时执行shell脚本
- Crontab 让linux定时执行shell脚本
- Linux Shell之init脚本与activemq init脚本设计亮点分析
- nios软核cpu中架构类shell的一种解决方式『linux 系统函数调用的方法』
- Xshell License Key
- linux shell截取字符串
- Shell 学习10 - Shell 注释
- 练习--hive查询实例和Shell去重
- Shell 学习9 - Shell 运算符
- Shell 学习8 - Shell 替换
- Shell 学习7 - Shell 特殊变量