How to run crontab job every week on Sunday

后端 未结 10 1094
忘掉有多难
忘掉有多难 2020-12-02 04:07

I\'m trying to figure out how to run a crontab job every week on Sunday. I think the following should work, but I\'m not sure if I understand correctly. Is the following cor

10条回答
  •  眼角桃花
    2020-12-02 04:32

    To have a cron executed on Sunday you can use either of these:

    5 8 * * 0
    5 8 * * 7
    5 8 * * Sun
    

    Where 5 8 stands for the time of the day when this will happen: 8:05.

    In general, if you want to execute something on Sunday, just make sure the 5th column contains either of 0, 7 or Sun. You had 6, so it was running on Saturday.

    The format for cronjobs is:

     +---------------- minute (0 - 59)
     |  +------------- hour (0 - 23)
     |  |  +---------- day of month (1 - 31)
     |  |  |  +------- month (1 - 12)
     |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
     |  |  |  |  |
     *  *  *  *  *  command to be executed
    

    You can always use crontab.guru as a editor to check your cron expressions.

提交回复
热议问题