1

I want to run a cronjob every two weeks on Sundays at midnight.

This is what I've tried.

 0 0 * * 0/2 /path/to/script

Is this correct? Will it execute the next Sunday and then every two weeks? I cant test it on my server at this point.. Please help.

Thanks.

user3270763
  • 125
  • 1
  • 3
  • 13

1 Answers1

3

AFAIK cron can't handle "every second week".

Instead, you could run it every Sunday at midnight and modify the script exit early if it's not one of the Sundays you want it to run.

If modification of the script is not possible, create a wrapper script that only calls the main script when it's a scheduled Sunday and call the wrapper from cron.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • here's a link http://stackoverflow.com/questions/350047/how-to-instruct-cron-to-execute-a-job-every-second-week can this be used? – user3270763 Dec 04 '15 at 22:34
  • @user3270763 that answer is in-lining a script into the cron executable. Personally, I would rather keep the cron simple and dedicate a script to handling the logic. It makes things more readable. Let's face it, cron is a *scheduling* tool - keep its function to that. Move the complicated date logic that is beyond cron's capability to somewhere where folks will expect to find it and can manage it. Another solution would be to create a list somewhere (db, text file, etc) of the dates you want it to run, and have the script look that up when deciding when to run. – Bohemian Dec 05 '15 at 00:04