-2

I want to create a cron job that will be launched a file at 2AM Thursdays, Fridays, and Saturdays.

For some reason I get really confused doing that.

Can someone give an example on how to do this?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Xozu
  • 1
  • 1
    Thank you for specifying that by weekend you meant Thursday, Friday and Saturday; I suspect lots of people here would otherwise have interpreted "weekend" as Saturday and Sunday. – user May 16 '17 at 17:29
  • 2
    Lucky guy, living in a country that has 3-day weekends... – dr_ May 17 '17 at 07:15

1 Answers1

3

The format of the cron table entry is as follows:

min hr date month weekday command

So, the entry for 2AM on Thu/Fri/Sat would be:

0 2 * * 4,5,6 /path/to/command

You can also use ranges:

0 2 * * 4-6 /path/to/command

The weekday field starts with 0 on Sunday (7 is also Sunday).

Some versions of cron will even let you spell it out:

0 2 * * Thu-Sat /path/to/command

If you want a handy tool that will explain cron table entries to you, this site might be pretty helpful.

DopeGhoti
  • 73,792
  • 8
  • 97
  • 133
  • 2
    It's probably worth noting that this is appropriate for a per-user cron file. If this is in a system-wide cron file (typically /etc/cron.\*/\*) you need to prefix the command with the user that the command should be executed as, making the format `min hour day month weekday user command`. – user May 16 '17 at 17:30
  • In addition to Michael's comment above, MOST times /etc/cron.*/* is used by package maintainers for package/program specific stuff. Of course, you as the sysadmin have the choice of adding other tasks there as well. – ivanivan May 16 '17 at 17:38
  • @Xozu Good! If this solves your issue, please consider [accepting the answer](http://unix.stackexchange.com/help/someone-answers). If you're happy with the answer, accepting it and maybe even upvoting it is the best way to say "Thank You!" :-) – Kusalananda May 17 '17 at 08:23