zoukankan      html  css  js  c++  java
  • [日期工具分享][Shell]为特定命令依次传入顺序日期执行

    [日期工具分享][Shell]为特定命令依次传入顺序日期执行

    使用方式:

    • <本脚本文件名(必要时需要全路径)> <要执行的命令所在的文件名> <开始日期> <结束日期>
    • 日期格式:yyyy-MM-dd

     

    脚本内容:

    #################################
    #! /bin/bash
    #################################
    # how to use:
    # thisFile yourCommdFile startDate endsDate
    # the format of date should be yyyy-MM-dd
    #################################
    
    # Time to Long
    bgnTimeL=`date -d "$2" +%s`
    endTimeL=`date -d "$3" +%s`
    ONE_DAY_TML=86400
    
    # Load the Time
    for (( i = $bgnTimeL; i < $endTimeL; i=`expr $i + $ONE_DAY_TML` )); do
        $1 `date -d @$i  "+%Y-%m-%d"`
    done
    
     

    简单演示:

    # usr @ XXxxx in ~ [17:58:05] 
    $ cat ~/bin/with-date-to-date-run.sh
    #################################
    #! /bin/bash
    
    # Time to Long
    bgnTimeL=`date -d "$2" +%s`
    endTimeL=`date -d "$3" +%s`
    ONE_DAY_TML=86400
    
    # Load the Time
    for (( i = $bgnTimeL; i < $endTimeL; i=`expr $i + $ONE_DAY_TML`  )); do
        $1 `date -d @$i  "+%Y-%m-%d"`
    done
    
    # usr @ XXxxx in ~ [18:04:40] 
    $ chmod +x ~/bin/with-date-to-date-run.sh                  
    
    # usr @ XXxxx in ~ [18:04:45] 
    $ ~/bin/with-date-to-date-run.sh echo 2009-12-29 2010-01-03
    2009-12-29
    2009-12-30
    2009-12-31
    2010-01-01
    2010-01-02
    
    # usr @ XXxxx in ~ [18:04:48] 
    $
    

     

     

    注意:

    本脚本第一个参数是要执行的命令,该命令的文件名中最好不要有空格。

  • 相关阅读:
    嵌入式Linux的调试技术
    硬件抽象层:HAL
    让开发板发出声音
    android 底层入门开发(二)
    android 底层开发入门(一)
    android驱动开发前的准备(五)
    Android驱动开发前的准备(四)
    Android驱动开发前的准备(三)
    Android驱动开发前的准备(二)
    Android驱动开发前的准备(一)
  • 原文地址:https://www.cnblogs.com/senwren/p/date-run-day.html
Copyright © 2011-2022 走看看