Results 1 to 8 of 8
First let me say that anything you suggest I'll have to read up on and learn the minimun to do the task.
My problem is I have a task which ...
- 05-05-2008 #1Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
What should it be written in??
First let me say that anything you suggest I'll have to read up on and learn the minimun to do the task.
My problem is I have a task which must run every 14days(every other wednesday).
I don't think cron(and tell me if I'm wrong) will do this or will it if I start the procedure after the 1st wednesday or if I give it a date to start and give it the 3/2 as the last qualifier.
What would be the best language to write a procedure like this in?
I do know some scripting but anything else will be foriegn.
thanks
Mace
- 05-05-2008 #2
Tricky one.
I'd bet tempted to use cron to tell it to run every wednesday, and write the script in such a way that it writes a file the first time it's run. Every other time it runs, it should check for the existence of that file -- if it finds it, it should delete it and then stop, if it doesn't it should create it, and continue the task as usual.
Understand?
This way it will run every other wednesday.Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 05-12-2008 #3Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
smolloy,
I understand, but that too seems a bit tricky,but thanks for the idea.
Mace
- 05-12-2008 #4Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
After I thought about if for a while it wasn't that tough.
I've written and tested and it works
I'm going to wait and see what the /3 does this week(see if the task executes or not and) go from there.
thanks
Mace
- 05-12-2008 #5
You mean you've tried my idea and it worked? Or you tried putting 3/2 into the cron job "day" field?
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 05-12-2008 #6Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
I've done both..I'll explain,
I've put the 3/2 in the cron statement and I'm going to see if it works
(thats the lazy mans way
)
BUT I also coded a little something and on another server tested it.
If the (a)file is there it deletes it and completes, but if the file isn't there it runs a command to do the backup thus creating the file.
Great idea, I wish I had thought of it.
I'll update this thread and let everyone know if the 3/2 works. It should run this week and not next. We will see.
Mace
- 05-23-2008 #7Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
Well here is a follow-up on my crontab problem.
I gave it a 3/2 in the last field(to run everyother Wednesday) and I figured it would run the week I initiated the crontab then skip the next,run,skip,etc...
Well it did run the 1st week(last week) but then it ran again this week

So I've decided to drop the logic into the script
thanks
Mace
- 05-26-2008 #8Just Joined!
- Join Date
- Dec 2007
- Posts
- 12
A more elegant solution to this problem would be to use a mod 2 calculation with the command "date +%U"
date +%U will give you the week number of the year and a mod 2 calculation will give you whether this number is even (congruent to 0 mod 2) or odd (1 mod 2). Have your script only execute its body when the number is even (or odd) and you will have a script that executes every two weeks.
This solution also works for the more general case of 'every n weeks' Just do date +%U mod n and have your script only execute when the result is 0.
There are some problems with this approach, such as when the year changes. But this would make your script run at most 1 extra time, which is not a big deal.


Reply With Quote