Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

crontab(5) defines the following fields:

       field         allowed values
       -----         --------------
       minute        0-59
       hour          0-23
       day of month  1-31
       month         1-12 (or names, see below)
       day of week   0-7 (0 or 7 is Sun, or use names)

and explains:

 Step values can be used in conjunction with ranges.  Following a range
 with ``/<number>'' specifies skips of the number's value through the
 range.  For example, ``0-23/2'' can be used in the hours field to specify
 command execution every other hour (the alternative in the V7 standard is
 ``0,2,4,6,8,10,12,14,16,18,20,22'').

So, no biweekly Jobs, as far as my understanding goes. I'm quite sure there are workarounds, what are yours? Or did I miss something?

share|improve this question
1  
The best answer I can find on this is here: unix.stackexchange.com/questions/1224/… –  Somantra Jul 3 '12 at 14:42
    
...and those answers on U&L would be the way I'd do it, @Somantra :-) –  voretaq7 Jul 3 '12 at 14:53
    
@voretaq7, I'd have said it was the canonical answer, but I didn't want to come across as pedantic ;-) –  Somantra Jul 3 '12 at 15:10

4 Answers 4

up vote 3 down vote accepted

You can have the thing run by cron every wednesday, then have the thing run decide if it is an even week or an odd week. for example:

#!/bin/bash
week=$(date +%U)
if [ $(($week % 2)) == 0 ]; then 
    echo even week
else 
    echo odd week
fi
share|improve this answer
    
This is a nice solution, however, doesn't really answer the question itself - I'd prefer not to taint the thing with schedule logic. Maybe I can integrate this with the link @Somantra gave. –  Roman Jul 3 '12 at 16:28
    
Alright, I must admit: this is the best solution so far. The link that @Somantra gave achieves the same results unecessarily complex IMHO (counting with UNIX time), but adding your approach directly to the cronjob (instead of into the script) in the same style makes it quite elegant. –  Roman Jul 30 '12 at 13:41

Anacron is a good workaround for the limitations of cron.

  • Anacron has a Recurrence Period parameter which you can set to 14.

period delay job-identifier command

14 15 test.daily /path/to/script.sh

share|improve this answer
    
Unfortunately, anacron can't be used. Forgot to mention that. –  Roman Jul 3 '12 at 17:41

From that explaination setting 3/2 on the week field should run the task on every other wednesday - its implicit, but i think doable.

share|improve this answer
    
no, this is equivalent to for(int i=3; i <=3 ; i+=2) {} since it is only going through this once, it doesn't matter if the "step" is 1 or 2. –  stew Jul 3 '12 at 15:43
    
What @stew said. Also, there's no "week field". –  Roman Jul 3 '12 at 16:30
    
By week field, i mean the "Day of week field' –  Journeyman Geek Jul 4 '12 at 0:07

Many crons (you didn't specify which you're using) support ranges. So something like

0 0 1-7,15-21 * 3

Would hit the first and third wednesdays of the month.

share|improve this answer
    
this is slightly more elegant than the "do it in the script" method, but remember to add a comment to your crontab (general rule of thumb: if you have more than one - or / involved it's probably worth commenting to describe the schedule) –  voretaq7 Jul 4 '12 at 3:18
    
I suspect this is wrong; it will cause the job to be run on the 1st-7th, and 15-21st, of each month, and every Wednesday as well. This from man 5 crontab: "The day of a command’s execution can be specified by two fields — day of month, and day of week. If both fields are restricted (ie, aren’t * ), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday" (my emphasis). –  MadHatter Oct 10 at 14:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.