LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 10-09-2007, 09:38 AM   #1
winlinfix
LQ Newbie
 
Registered: Jun 2007
Posts: 3

Rep: Reputation: 0
crontab every 2 days


HI,

how to run crontab every 2 days???

0 0 2 * * will work?
 
Old 10-09-2007, 09:59 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Quote:
0 0 2 * * will work?
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.
 
Old 10-09-2007, 10:09 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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:
Code:
man 5 crontab

Last edited by matthewg42; 10-09-2007 at 10:15 AM.
 
Old 10-09-2007, 10:34 AM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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.
 
Old 10-09-2007, 10:49 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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 10:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Has it ever been 'one of those days'? hacker supreme General 24 07-03-2007 06:36 PM
Crontab every 15 days, isn't possible? deqmacrom Linux - General 3 04-07-2005 03:31 AM
having one of THOSE DAYS ! qwijibow General 3 11-10-2004 05:13 AM
once in how often? twice in two days!? andzerger Linux - Security 1 02-20-2004 06:45 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 01:35 PM


All times are GMT -5. The time now is 05:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration