Coder Perfect

How can I schedule a crontab job to run every week on Sunday?

Problem

I’m attempting to find out how to execute a crontab job on Sunday every week. I believe the following should work, but I’m not sure I understand. Is the following statement true?

5 8 * * 6

Asked by dev_fight

Solution #1

A description of the crontab format may be found here.

# 1. Entry: Minute when the process will be started [0-60]
# 2. Entry: Hour when the process will be started [0-23]
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
# 4. Entry: Month of the year when the process will be started [1-12]
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
#
# all x min = */x

As a result, your 5 8 * * 0 would start at 8:05 every Sunday.

Answered by Bjoern Rennhak

Solution #2

You can use either of these to have a cron run on Sunday:

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

The number 5 8 denotes the time of day when this will occur: 8:05.

In general, if you want to do something on Sunday, make sure the 5th column has either 0, 7 or Sun in it. Because you had six people, it was held 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

To double-check your cron expressions, you may always use crontab.guru as an editor.

Answered by fedorqui ‘SO stop harming’

Solution #3

The crontab file should be formatted as follows.

{minute} {hour} {day-of-month} {month} {day-of-week} {user} {path-to-shell-script}

So, to run each Sunday at midnight (Sunday is generally 0 but 7 in some odd circumstances), do the following:

0 0 * * 0 root /path_to_command

Answered by xShirase

Solution #4

The crontab website displays the results in real time: https://crontab.guru/#5 8 * * 0

Answered by TechPassionate

Solution #5

You must make sure that your cron values are inside the ranges when specifying them. Some crons, for example, employ a 0-7 range for the day of week, with 0 and 7 representing Sunday. We don’t have any (check below).

Seconds: 0-59
Minutes: 0-59
Hours: 0-23
Day of Month: 1-31
Months: 0-11
Day of Week: 0-6

reference: https://github.com/ncb000gt/node-cron

Answered by Mendon Ashwini

Post is based on https://stackoverflow.com/questions/16717930/how-to-run-crontab-job-every-week-on-sunday