Crontab每月定时任务的几个demo

发布于 分类 Linux

29天前 有1个用户阅读过

crontab每月定时任务场景
# crontab定时任务
# 分 时 日 月 星期 要执行的命令

# 每个月第一天
0 0 1 * * (shell script)

# 每个月最后一天
0 0 28-31 * * [ `date -d tomorrow +\%e` -eq 1 ] && (shell script)

# 每个月第一个星期6
0 0 1-7 * 6 (shell script) 

-- The End --

本文标题: Crontab每月定时任务的几个demo

本文地址: https://seonoco.com/blog/crontab-demo

点赞 0
感谢支持
0
多谢反馈
评论 0
打赏

支持微信/支付宝

评论 ( 当前有 2 条评论 )

网友

最新最早
  • 网友2019-12-02 11:36:07
    Unfortunately, the day-of-month and day-of-week is an OR proposition where either will cause the job to run, as per the manpage:

    Commands are executed by cron when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time.

    The day of a command's execution can be specified by two fields - day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time. For example, 30 4 1,15 * 5 would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

    Hence you need to set up your cron job to run on every one of those days and immediately exit if it's not Saturday.
  • noco @ 楼上 2019-12-02 16:43:14
    Thanks for your information.
    I found a solution from
    [https://stackoverflow.com/questions/11683387/run-every-2nd-and-4th-saturday-of-the-month/26425901]

    30 4 1,15 * * [ `date +\%u` = 5 ] && (shell script)