crontab help
I want to run 4 scripts (scr1-scr4) in following way:
scr1: every first Thursday 02:30 every month scr2: every second Thursday 02:30 every month scr3: every third Thursday 02:30 every month scr4: every fourth Thursday 02:30 every month How will the crontab look like ? |
Maybe this would work?
Code:
30 2 1-7 * 4 scr1 |
Thanks - but what will happen if Thursday is on day 29-31 ?
|
Quote:
|
Yes - your are right - my mistake.
What I want to do is run scr1 on the first Thursday of every month, scr2 on the following Thursday ... and so on As an example, next month in August Thursdays occur on: 2 -> scr1 9 -> scr2 16 -> scr3 23 -> scr4 30 -> scr1 Is there a way to get it done with date function ? |
So what would happen in your example in September?
Would it run like this: Aug 2 -> scr1 Aug 9 -> scr2 Aug 16 -> scr3 Aug 23 -> scr4 Aug 30 -> scr1 Sep 6 -> scr1 Or would you go to scr2 on Sep 6 since scr1 already ran on Aug 30? If you want to restart with scr1 on the first Thurs of every month, regardless of which code you ended on in the previous month, I would just add a 5th entry to the crontab: Code:
30 2 1-7 * 4 /path/to/scr1 If you want to keep the 1,2,3,4,1,2,3,4 pattern going (meaning scr1 will not run on the first thurs of every month, it will steadily move to the last thurs of the month, then the fourth, then the third, second, first, and back to the last), then I would probably set up one crontab entry to do something like this: Code:
30 2 * * 4 /path/to/scrmaster It could look something like this: Code:
#!/bin/bash |
Thanks for your input - I will go for:
30 2 1-7 * 4 /path/to/scr1 30 2 8-14 * 4 /path/to/scr2 30 2 15-21 * 4 /path/to/scr3 30 2 22-28 * 4 /path/to/scr4 30 2 29-31 * 4 /path/to/scr1 |
FYI quoted from the cron wiki
Quote:
http://en.wikipedia.org/wiki/Cron 30 2 1-7 * * [ `date +%u` = 4 ] && /path/to/scr1 |
Don't understand how this works ... in the example you gave 30 2 1-7 * * [ `date +%u` = 4 ] && /path/to/scr1 both "day of month" and "day of week" are not-restricted ('*') so the exception is not valid here ... or ?
|
Correct.
Here is another way for running a script on the 1st Thursday of the month: Quote:
As stated the problem with suicidaleggroll's suggestion is that your script will run on days 1-7 and also runs on Thurs. Other examples can be found by googling... |
I didn't realize that the day of month and day of week fields behaved as an "or" rather than an "and". Thanks for the clarification.
In that case my earlier suggestion will not work, you'll have to go with one of michaelk's |
Traditionally, you'd write a master script that ran every Thursday, and then in the top of that script do any fine calcs as to which fn/sub-script to action.
Just an alternative to think about. |
OK - that makes sense
|
Yeah, also more portable :)
|
All times are GMT -5. The time now is 04:50 PM. |