【问题标题】:Auto set cron bash script?自动设置 cron bash 脚本?
【发布时间】:2011-05-24 15:33:32
【问题描述】:

如何让一些脚本根据从数据库或其他方式获取的时间自动设置它的执行?

有什么简单明了的例子吗?

【问题讨论】:

    标签: bash cron


    【解决方案1】:

    假设:

    • 您有一个脚本,用于从数据库中选择执行日期和命令
    • 此脚本的输出格式为:[[CC]YY]MMDDhhmm <space> command_name and_args

    例如,这将从标准输入中读取成对的“日期”“命令”:

    while read exectime command
    do
        echo "$command" | at -t "$exectime"
    done
    

    像这样使用它:

    /path/to/script_select_from_database | ./the_above_script
    

    或者这个

    exectime="$1"
    shift
    echo "$@" | at -t "$exectime"
    

    调用它"

    ./this_script `/path/to/script_select_from_database`
    

    将两者结合到一个脚本和/或任何其他变体中...

    脚本将您的命令排入队列以使用at 命令执行。见man at

    【讨论】:

      猜你喜欢
      • 2021-12-21
      • 2022-06-13
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      相关资源
      最近更新 更多