29

How do I set a cron job to run twice a week?

I know how to set a cron job for every week:

0 0 * * 0
cmbuckley
  • 40,217
  • 9
  • 77
  • 91
Elby
  • 1,624
  • 3
  • 23
  • 42
  • 4
    does bi-weekly mean every other week, or twice a week - if it's every other week then please see http://stackoverflow.com/questions/350047/how-to-instruct-cron-to-execute-a-job-every-second-week – Anya Shenanigans Jan 02 '13 at 12:32

3 Answers3

58

How about the following:

0 0 * * 1,4

This sets the day of week to Monday (1) and Thursday (4). You can choose any values 0–7 (both 0 and 7 are Sunday).

For a more readable crontab, you can also use names:

0 0 * * MON,THU

See also: How to instruct cron to execute a job every second week?

Community
  • 1
  • 1
cmbuckley
  • 40,217
  • 9
  • 77
  • 91
  • I want to set cron for 2 times in a Month. Set cron for once at a 2 week – Elby Jan 09 '13 at 05:14
  • 7
    Biweekly is an ambiguous phrase; in the UK it tends to mean twice a week. For "every other week" we use *fortnightly* :-) See Petesh's comment above for a related question. – cmbuckley Jan 09 '13 at 09:34
5

In reply to Elby question :

0 0 1,15 * *

This will set cronjob for (fortnight) 2 times in a Month i.e 1st day and 15th day of a month.

Vikrant Ramteke
  • 319
  • 4
  • 5
2

These answers are great, but I wanted to share a tool I found right after looking at this question and answers called crontab.guru. I'm not affiliated, I just thought it was a nice tool.

crontab.guru for 'At 00:00 on Monday and Thursday.'

Matt Klein
  • 7,856
  • 6
  • 45
  • 46