How to run crontab job every week on Sunday

LinuxCrontab

Linux Problem Overview


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 correct?

5 8 * * 6

Linux Solutions


Solution 1 - Linux

Here is an explanation of the crontab format.

# 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

So according to this your 5 8 * * 0 would run 8:05 every Sunday.

Solution 2 - Linux

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.

Solution 3 - Linux

Following is the format of the crontab file.

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

So, to run each sunday at midnight (Sunday is 0 usually, 7 in some rare cases) :

0 0 * * 0 root /path_to_command

Solution 4 - Linux

The crontab website gives the real time results display: https://crontab.guru/#5_8_*_*_0

enter image description here

Solution 5 - Linux

When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not(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

Solution 6 - Linux

I think you would like this interactive website, which often helps me build complex Crontab directives: https://crontab.guru/

Solution 7 - Linux

@weekly work better for me!

example,add the fellowing  crontab -e ,it will work in every sunday 0:00 AM
@weekly /root/fd/databasebackup/week.sh >> ~/test.txt

Solution 8 - Linux

Cron job expression in a human-readable way crontab builder

Solution 9 - Linux

10 * * * Sun

Position 1 for minutes, allowed values are 1-60
position 2 for hours, allowed values are 1-24
position 3 for day of month ,allowed values are 1-31
position 4 for month ,allowed values are 1-12 
position 5 for day of week ,allowed values are 1-7 or and the day starts at Monday. 

Solution 10 - Linux

* * * * 0 

you can use above cron job to run on every week on sunday, but in addition on what time you want to run this job for that you can follow below concept :

* * * * *  Command_to_execute
- � � � -
| | | | |
| | | | +�� Day of week (06) (Sunday=0) or Sun, Mon, Tue,...
| | | +���- Month (112) or Jan, Feb,...
| | +����-Day of month (131)
| +������� Hour (023)
+��������- Minute (059)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondev_fightView Question on Stackoverflow
Solution 1 - LinuxBjoern RennhakView Answer on Stackoverflow
Solution 2 - LinuxfedorquiView Answer on Stackoverflow
Solution 3 - LinuxxShiraseView Answer on Stackoverflow
Solution 4 - LinuxTechPassionateView Answer on Stackoverflow
Solution 5 - LinuxMendon AshwiniView Answer on Stackoverflow
Solution 6 - LinuxjasperView Answer on Stackoverflow
Solution 7 - Linux未来陆家嘴顶尖的投资人View Answer on Stackoverflow
Solution 8 - LinuxVytautasView Answer on Stackoverflow
Solution 9 - LinuxBachan JosephView Answer on Stackoverflow
Solution 10 - LinuxSiddharth BhandariView Answer on Stackoverflow