public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] crontab - "and' condition
@ 2014-09-18 16:44 Joseph
  2014-09-18 16:57 ` Kerin Millar
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Joseph @ 2014-09-18 16:44 UTC (permalink / raw
  To: gentoo-user

I want to run a cron job only once a month.  The problem is the computer is only on on weekdays Mon-Fri. 1-5

cron tab as this below is an "or" condition as it has entries in Days of the Months and Day of the  Week

5 18 1 * 2  rsync -av ...

so it will run on days 1 or Tuesday of each months.

Is it possible to create "and" condition, eg. run it on Tuesday between days 1 to 7; depend on which day Tuesday falls on? 

-- 
Joseph


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-18 16:44 [gentoo-user] crontab - "and' condition Joseph
@ 2014-09-18 16:57 ` Kerin Millar
  2014-09-18 17:14 ` Alan McKinnon
  2014-09-19  7:47 ` Stephan Müller
  2 siblings, 0 replies; 9+ messages in thread
From: Kerin Millar @ 2014-09-18 16:57 UTC (permalink / raw
  To: gentoo-user

On 18/09/2014 17:44, Joseph wrote:
> I want to run a cron job only once a month.  The problem is the computer
> is only on on weekdays Mon-Fri. 1-5
>
> cron tab as this below is an "or" condition as it has entries in Days of
> the Months and Day of the  Week
>
> 5 18 1 * 2  rsync -av ...
>
> so it will run on days 1 or Tuesday of each months.
>
> Is it possible to create "and" condition, eg. run it on Tuesday between
> days 1 to 7; depend on which day Tuesday falls on?

You can place a script in /etc/cron.monthly. The run-crons script is 
scheduled to execute every 10 minutes, and it will ensure that your 
script is executed on a monthly schedule. This is true of both cronie 
and vixie-cron.

--Kerin


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-18 16:44 [gentoo-user] crontab - "and' condition Joseph
  2014-09-18 16:57 ` Kerin Millar
@ 2014-09-18 17:14 ` Alan McKinnon
  2014-09-19  4:21   ` Joseph
  2014-09-19  7:47 ` Stephan Müller
  2 siblings, 1 reply; 9+ messages in thread
From: Alan McKinnon @ 2014-09-18 17:14 UTC (permalink / raw
  To: gentoo-user

On 18/09/2014 18:44, Joseph wrote:
> I want to run a cron job only once a month.  The problem is the computer
> is only on on weekdays Mon-Fri. 1-5
> 
> cron tab as this below is an "or" condition as it has entries in Days of
> the Months and Day of the  Week
> 
> 5 18 1 * 2  rsync -av ...
> 
> so it will run on days 1 or Tuesday of each months.
> 
> Is it possible to create "and" condition, eg. run it on Tuesday between
> days 1 to 7; depend on which day Tuesday falls on?


Not in one line.

Split it into two crontab entries.



-- 
Alan McKinnon
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-18 17:14 ` Alan McKinnon
@ 2014-09-19  4:21   ` Joseph
  2014-09-19  7:09     ` Alan McKinnon
  0 siblings, 1 reply; 9+ messages in thread
From: Joseph @ 2014-09-19  4:21 UTC (permalink / raw
  To: gentoo-user

On 09/18/14 19:14, Alan McKinnon wrote:
>On 18/09/2014 18:44, Joseph wrote:
>> I want to run a cron job only once a month.  The problem is the computer
>> is only on on weekdays Mon-Fri. 1-5
>>
>> cron tab as this below is an "or" condition as it has entries in Days of
>> the Months and Day of the  Week
>>
>> 5 18 1 * 2  rsync -av ...
>>
>> so it will run on days 1 or Tuesday of each months.
>>
>> Is it possible to create "and" condition, eg. run it on Tuesday between
>> days 1 to 7; depend on which day Tuesday falls on?
>
>
>Not in one line.
>
>Split it into two crontab entries.

Interesting.  How do you split cron job? I couldn't find any examples.

-- 
Joseph


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-19  4:21   ` Joseph
@ 2014-09-19  7:09     ` Alan McKinnon
  2014-09-20 16:09       ` Michael Orlitzky
  0 siblings, 1 reply; 9+ messages in thread
From: Alan McKinnon @ 2014-09-19  7:09 UTC (permalink / raw
  To: gentoo-user

On 19/09/2014 06:21, Joseph wrote:
> On 09/18/14 19:14, Alan McKinnon wrote:
>> On 18/09/2014 18:44, Joseph wrote:
>>> I want to run a cron job only once a month.  The problem is the computer
>>> is only on on weekdays Mon-Fri. 1-5
>>>
>>> cron tab as this below is an "or" condition as it has entries in Days of
>>> the Months and Day of the  Week
>>>
>>> 5 18 1 * 2  rsync -av ...
>>>
>>> so it will run on days 1 or Tuesday of each months.
>>>
>>> Is it possible to create "and" condition, eg. run it on Tuesday between
>>> days 1 to 7; depend on which day Tuesday falls on?
>>
>>
>> Not in one line.
>>
>> Split it into two crontab entries.
> 
> Interesting.  How do you split cron job? I couldn't find any examples.
> 


No wait, that won't work. What you want to accomplish cannot be done
with a single crontab job.

Use periodic/monthly like the other poster said or use anacron so the
job will run when the machine is next powered on.


-- 
Alan McKinnon
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-18 16:44 [gentoo-user] crontab - "and' condition Joseph
  2014-09-18 16:57 ` Kerin Millar
  2014-09-18 17:14 ` Alan McKinnon
@ 2014-09-19  7:47 ` Stephan Müller
  2014-09-20 17:40   ` Joseph
  2 siblings, 1 reply; 9+ messages in thread
From: Stephan Müller @ 2014-09-19  7:47 UTC (permalink / raw
  To: gentoo-user

Am 18.09.2014 um 18:44 schrieb Joseph:
> I want to run a cron job only once a month.  The problem is the computer is only on on weekdays Mon-Fri. 1-5
> cron tab as this below is an "or" condition as it has entries in Days of the Months and Day of the  Week
> 
> 5 18 1 * 2  rsync -av ...
> 
> so it will run on days 1 or Tuesday of each months.
> Is it possible to create "and" condition, eg. run it on Tuesday between days 1 to 7; depend on which day Tuesday falls on?

You can run it every Tuesday and check for day of month externally:

5 18 * * 2   test $(date +%d) -le 7 && rsync -av ...

or run it on

5 18 1-7 * * and test for Tuesdays, but the former gives less useless invocations.

 ~frukto 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-19  7:09     ` Alan McKinnon
@ 2014-09-20 16:09       ` Michael Orlitzky
  2014-09-21  7:57         ` Peter Humphrey
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Orlitzky @ 2014-09-20 16:09 UTC (permalink / raw
  To: gentoo-user

On 09/19/2014 03:09 AM, Alan McKinnon wrote:
> 
> No wait, that won't work. What you want to accomplish cannot be done
> with a single crontab job.
> 
> Use periodic/monthly like the other poster said or use anacron so the
> job will run when the machine is next powered on.
> 

Actually, Gentoo's sys-process/cronbase is supposed to make sure that
this happens. But the way it works is poorly (i.e. not) specified. This
is one of my favorite old "seriously?" bugs:

  https://bugs.gentoo.org/show_bug.cgi?id=69777



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-19  7:47 ` Stephan Müller
@ 2014-09-20 17:40   ` Joseph
  0 siblings, 0 replies; 9+ messages in thread
From: Joseph @ 2014-09-20 17:40 UTC (permalink / raw
  To: gentoo-user

On 09/19/14 09:47, Stephan Müller wrote:
>Am 18.09.2014 um 18:44 schrieb Joseph:
>> I want to run a cron job only once a month.  The problem is the computer is only on on weekdays Mon-Fri. 1-5
>> cron tab as this below is an "or" condition as it has entries in Days of the Months and Day of the  Week
>>
>> 5 18 1 * 2  rsync -av ...
>>
>> so it will run on days 1 or Tuesday of each months.
>> Is it possible to create "and" condition, eg. run it on Tuesday between days 1 to 7; depend on which day Tuesday falls on?
>
>You can run it every Tuesday and check for day of month externally:
>
>5 18 * * 2   test $(date +%d) -le 7 && rsync -av ...
>
>or run it on
>
>5 18 1-7 * * and test for Tuesdays, but the former gives less useless invocations.
>
> ~frukto

Thanks, very cleaver, I knew there must be a solution.

-- 
Joseph


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] crontab - "and' condition
  2014-09-20 16:09       ` Michael Orlitzky
@ 2014-09-21  7:57         ` Peter Humphrey
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Humphrey @ 2014-09-21  7:57 UTC (permalink / raw
  To: gentoo-user

On Saturday 20 September 2014 12:09:32 Michael Orlitzky wrote:

> This is one of my favorite old "seriously?" bugs:
> 
>   https://bugs.gentoo.org/show_bug.cgi?id=69777

Round and round and round we go. Wonderful!

-- 
Regards
Peter



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-09-21  7:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-18 16:44 [gentoo-user] crontab - "and' condition Joseph
2014-09-18 16:57 ` Kerin Millar
2014-09-18 17:14 ` Alan McKinnon
2014-09-19  4:21   ` Joseph
2014-09-19  7:09     ` Alan McKinnon
2014-09-20 16:09       ` Michael Orlitzky
2014-09-21  7:57         ` Peter Humphrey
2014-09-19  7:47 ` Stephan Müller
2014-09-20 17:40   ` Joseph

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox