【问题标题】:crontab exclude specific date onlycrontab 仅排除特定日期
【发布时间】:2014-06-26 19:40:51
【问题描述】:

如何编写一个排除特定日期的 cron。

假设:我需要在周末每 30 分钟运行一次 crontab 下午 6 点到晚上 9 点,并且只想排除 2014 年 5 月 10 日。

有可能吗?我怎么写这个?或者有什么替代方法吗?请提出建议。

【问题讨论】:

标签: unix ubuntu cron crontab


【解决方案1】:

您的 crontab 可能必须指向一个 shell 脚本,该脚本仅在日期不是 2014 年 5 月 10 日时才会运行该命令。

在您的 crontab 中: 0,30 18-21 * * 6,7 /path/to/your_script.sh

your_script.sh 可能如下所示:

#!/bin/bash
TODAY=$(date "+%Y%m%d")
if [ "$TODAY" -ne "20140510" ]; then
  your_command_to_run
else
  exit 0
fi 

Reference

【讨论】:

    猜你喜欢
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2021-07-03
    • 2020-10-19
    • 2021-11-25
    相关资源
    最近更新 更多