Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Aug 2001 15:47:25 +0300
From:      Odhiambo Washington <wash@wananchi.com>
To:        freebsd-questions@FreeBSD.ORG
Cc:        thomas@pbegames.com, ahl@austclear.com.au
Subject:   Re: Crontab - Biweekly events?
Message-ID:  <20010802154725.B24967@everest.wananchi.com>
In-Reply-To: <200107192337.JAA04489@tungsten.austclear.com.au>
References:  <thomas@pbegames.com> <5.1.0.14.2.20010719175024.02510170@pbegames.com> <200107192337.JAA04489@tungsten.austclear.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help

* Tony Landells <ahl@austclear.com.au> [20010720 02:37]: writing on the subject 'Re: Crontab - Biweekly events?'
Tony> 
Tony> thomas@pbegames.com said:
Tony> > I have a task I want to run every other week on a specific day, say
Tony> > Tuesday. I can't see a way to convince cron to do this. Anyone know
Tony> > how? 
Tony> 
Tony> You can't.  Cron doesn't support this.
Tony> 
Tony> However, what you can do is wrap your stuff in a script that either
Tony> creates a "flag" file somewhere (if it doesn't exist) and runs your
Tony> stuff or deletes the flag file (if it exists) and exits.  Then run
Tony> that every Tuesday from crontab.
Tony> 
Tony> Alternatively, you can use "at" to schedule the job initially, and
Tony> then have it reschedule itself for two weeks time.  You probably
Tony> want it to email you a reminder that it's rescheduled itself too...
Tony> 
Tony> Actually, I like the first one a lot, since you could also use it
Tony> for every second day, month, ...
Tony> 
Tony> Actually, a generic "wrapper" could even be made to run the task
Tony> every <arbitrary number> of days/weeks/years/...

Long time ago (not quite long really) someone called Crist J. Clark posted
something that would seem to diagree with Tony's assertion that this
cannot be done in a crontab. I will paste here the discussion verbatim:

<snip>
> > I am looking for a crontab entry that runs my command on
> > the first thursday of every month at 6 am. I thought the
> > following would work but it doesn't:
> >
>
> AFAIK, this cannot be done with a crontab entry. However, you may be
> able to wrap /path/to/my/command with a script that exits if the day of the
> month is greater than 7, and then use a crontab entry that simply
> specifies to run on every thursday.

No need for a wrapper, just put it all in the crontab,
  0 6 * * 4     if [ `date +\%d` -le 7 ]; then /path/to/my/command; fi

--
Crist J. Clark                           cjclark@alum.mit.edu

</snip>


Maybe that will give this guy an insight.
I've been looking into running a cron job like this and was attempting
this, although it's not yet worked


DATE=`date +\%w` # Will give me the numerical date. 

alligator# bash
wash:/home/wash# DATE=`date +\%w`
wash:/home/wash# echo $DATE
4

So today is Thursday, the 4th day. Tuesday is then the 2nd day.

Can't we then do something like

if [ $DATE = "2" ];  then  /run/some/command ; fi

to make his command run every Tuesday??

Can't that be made to work?

Please lemme know.


-Wash

--
Odhiambo Washington
Wananchi Online Ltd.,
wash@wananchi.com 1st Flr Loita Hse.
Tel: 254 2 313985 Loita Street.,
Fax: 254 2 313922 PO Box 10286,00100-NAIROBI,KE.

When one rows, it is not the rowing which moves the ship. Rowing is only a 
magical ceremony by means of which, one compels a demon to move the ship. 
-Friedrich Nietzsche 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010802154725.B24967>