Crontab、定时作业、节假日

Crontab, scheduled jobs, on holidays

我写了一个 shell 脚本来监视 Rest API,当它关闭时 shell 脚本发送两封邮件,一封给开发人员,另一封给经理。问题是我需要这个频率:

¿如何在假期和工作日之间丢弃?

您需要几个条目:

  1. 办公时间每 15 分钟一班

    */15 09-18 * * * yourscript.sh

  2. 仅向经理发送电子邮件,在脚本中添加一个 if 以检查时间并仅向经理发送电子邮件

    00 06-09,18-23 * * * yourscript.sh

  3. 每三个小时发送一次

    00 00,03,06 * * * yourscript.sh

如果没有 运行 假期,cron 将无法提供帮助,您需要从不同的来源获取一个列出所有假期的文件,然后在您的脚本中添加一个 if。

#!/bin/sh 
if [ grep -q `date +%F` /random_location/holidays.txt]; then    
   exit 0   
fi

# Continue your script from here

如果 运行 不是节假日,请将该日期输入 holidays.txt。在 crontab 中有一个条目,如

* * * * * grep -q `date -I` holidays.txt || yourscript.sh

最好为 holidays.txt 和 yourscript.sh

使用完整路径