Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-09-2007, 08:38 AM
|
#1
|
LQ Newbie
Registered: Jun 2007
Posts: 3
Rep:
|
crontab every 2 days
HI,
how to run crontab every 2 days???
0 0 2 * * will work?
|
|
|
10-09-2007, 08:59 AM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
That will run the command on the second day of the month, not every two days.
The crontab fields are:
minute : 0-59
hour : 0-23
day-of-month : 0-31
month-of-year: 1-12
day-of-week : 0-6
(0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat)
So, the closest to running the job every two days would be:
0 0 0 0 2,4,6 <command>
which would run the job every Tuesday, Thursday, and Saturday.
|
|
|
10-09-2007, 09:09 AM
|
#3
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
What about this?
Code:
0 0 */2 * * command
Two things to note:
1. With varying end-of-month days you might get only 1 day between runs sometimes... /2 means every two days, so if the range is 1-31, that would be 1,3,5 ... 31 and then the job would run again on the first of the next month, only one day later.
2. I don't know if the "/" syntax is respected by all implementations of cron however. Check the crontab manual page in section 5 of the manual, i.e. to find out, do command:
Last edited by matthewg42; 10-09-2007 at 09:15 AM.
|
|
|
10-09-2007, 09:34 AM
|
#4
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
Oops, I didn't read far enough into the man page. The /2 (called 'stepping') should run the job at two day intervals, beginning on the second day of the month.
For months with an even number of days, that would work. For months with an odd number of days, that would probably result in a three day interval before the job runs again.
|
|
|
10-09-2007, 09:49 AM
|
#5
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
I'm not sure if /2 stepping on month day will end up with runs on 2, 4, 6 ... or 1, 3, 5 ...
The manual page is a little ambiguous about this. From the manual page it is clear that a range of 0-n/2 will result in even numbers 0, 2, 4, ... n; and for a range 1-n/2 there will be runs at 1,3,5 ... n.
What the * means is not well defined. For minutes in an hour it does state that */2 will start at 0, but there is never a day 0 of the month, so maybe */2 would mean 1,3,5... in that case. Only an experiment or examination of the source will tell. It may even vary according to which cron implementation is being used.
If someone knows for sure, either by looking at the source, or by an experiment, please post. If you do, please also post the cron implementation and version.
I use the default cron which comes with Ubuntu 7.04, and that is anacron 2.3. With this version using a day-of-month vale of */2 ran today - an odd-numbered day.
Perhaps to avoid this ambiguity, you should use "1-31/2" instead of "*/2".
Last edited by matthewg42; 10-09-2007 at 09:51 AM.
|
|
|
All times are GMT -5. The time now is 07:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|