Re: complex crontab query

2003-10-07 Thread Odhiambo Washington
* Matthew Seaman [EMAIL PROTECTED] [20030930 21:08]: wrote:
 On Tue, Sep 30, 2003 at 07:49:57PM +0300, Odhiambo Washington wrote:
  This question was asked and was answered by Crist J. Clark some years gone.
  Google could not help me so I beg to ask here:
 
 crontab(5) should be all you need.
  
  I would like to run a script via crontab every
  
  1. 3rd day and 28th day of each month (seems easy)
 
 Crontab line like:
 
   23 11 3,28 * * your_script
 
 will run at 11:23am on the 3rd and 28th of each month.
 
  2. Every first Thursday of the month
 
 This one is slightly trickier -- the best you can do with crontab is
 either every Thursday, and add logic to your script to detect if it's
 on or before the 7th of the month (or conversely for the first 7 days
 of each month, and have the script check if it's Thursday): something
 like --
 
   23 11 * * Thu   [ $(date +%d) -lt 8 ]  your_script
 
 ( or
 
   23 11 1-7 * *   [ $(date +%a) = Thu ]  your_script
 
 but the former is probably preferable)

How does that differ with the following?

23 11 * * 4 if [ `date +\%d` -le 7 ]; then /path/to/my/command; fi



 

Best regards,
Odhiambo Washington
Wananchi Online Ltd.

--+-
 Odhiambo W. wash(at)wananchi(dot)com   . WANANCHI ONLINE LTD (Nairobi, KE)
 http://www.wananchi.com/email/ . 1ere Etage, Loita Hse, Loita St.,
 Mobile: (+254) 722 743 223 . # 10286, 00100 NAIROBI
--+-
What the hell, go ahead and put all your eggs in one basket.



Do not be afraid of those who kill the body but cannot kill the soul.
Rather be afraid of the One who can destroy both soul and body in hell.
Matthew 10:28
 



pgp0.pgp
Description: PGP signature


Re: complex crontab query

2003-10-07 Thread Matthew Seaman
On Tue, Oct 07, 2003 at 05:53:47PM +0300, Odhiambo Washington wrote:
 * Matthew Seaman [EMAIL PROTECTED] [20030930 21:08]: wrote:

23 11 * * Thu   [ $(date +%d) -lt 8 ]  your_script

 How does that differ with the following?
 
 23 11 * * 4 if [ `date +\%d` -le 7 ]; then /path/to/my/command; fi

TIMTOWTDI.

Both lines should have the same effect overall, although I neglected
to escape the % sign in what I wrote, which is not a good move in a
crontab file.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature


RE: complex crontab query

2003-09-30 Thread Charles Howse
 This question was asked and was answered by Crist J. Clark 
 some years gone.
 Google could not help me so I beg to ask here:
 
 I would like to run a script via crontab every
 
 1. 3rd day and 28th day of each month (seems easy)
 2. Every first Thursday of the month

One solution would be to program the logic into your script, then run
the script every day from crontab.
Example bash pseudo-code:
If day-of-month = 3 or 28 ; then
do some stuff
Elif day-of-month = 7 and day-of-week = Thursday ; then
do the same stuff
fi


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: complex crontab query

2003-09-30 Thread Matthew Seaman
On Tue, Sep 30, 2003 at 07:49:57PM +0300, Odhiambo Washington wrote:
 This question was asked and was answered by Crist J. Clark some years gone.
 Google could not help me so I beg to ask here:

crontab(5) should be all you need.
 
 I would like to run a script via crontab every
 
 1. 3rd day and 28th day of each month (seems easy)

Crontab line like:

  23 11 3,28 * * your_script

will run at 11:23am on the 3rd and 28th of each month.

 2. Every first Thursday of the month

This one is slightly trickier -- the best you can do with crontab is
either every Thursday, and add logic to your script to detect if it's
on or before the 7th of the month (or conversely for the first 7 days
of each month, and have the script check if it's Thursday): something
like --

  23 11 * * Thu   [ $(date +%d) -lt 8 ]  your_script

( or

  23 11 1-7 * *   [ $(date +%a) = Thu ]  your_script

but the former is probably preferable)

Cheers,

Matthew 

-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature


Re: complex crontab query

2003-09-30 Thread Matthew Hunt
Here are untested examples that I think should work.  They run the job
at 3:00 am (the first two fields).

On Tue, Sep 30, 2003 at 07:49:57PM +0300, Odhiambo Washington wrote:

 1. 3rd day and 28th day of each month (seems easy)

0  3  3,28  *  *  mycommand

 2. Every first Thursday of the month

0  3  1-7   *  *  [ `date +%a` = Thu ]  mycommand

-- 
Matthew Hunt [EMAIL PROTECTED] * Science rules.
http://www.pobox.com/~mph/   *
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: complex crontab query

2003-09-30 Thread Kai Grossjohann
Matthew Hunt [EMAIL PROTECTED] writes:

 2. Every first Thursday of the month

 0  3  1-7   *  *  [ `date +%a` = Thu ]  mycommand

My understanding is that putting more than one condition in it
performs a logical conjunction.  So wouldn't it work to do like this?

# minute hour dom month dow command
031-7 * 4   mycommand

But I'm not an expert.

Kai

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: complex crontab query

2003-09-30 Thread Matthew Hunt
On Tue, Sep 30, 2003 at 10:56:20PM +0200, Kai Grossjohann wrote:

 My understanding is that putting more than one condition in it
 performs a logical conjunction.  So wouldn't it work to do like this?
 
 # minute hour dom month dow command
 031-7 * 4   mycommand

I thought that might be the case, but the man page says:

# Commands are executed by cron(8) when the minute, hour, and month of
# year fields match the current time, and when at least one of the two
# day fields (day of month, or day of week) matches the current time
# (see ``Note'' below).

...

# Note: The day of a command's execution can be specified by two fields
# -- day of month, and day of week.  If both fields are restricted (ie,
# aren't *), the command will be run when either field matches the
# current time.  For example, ``30 4 1,15 * 5'' would cause a command
# to be run at 4:30 am on the 1st and 15th of each month, plus every
# Friday.

-- 
Matthew Hunt [EMAIL PROTECTED] * Salvage, like other forms of virtue, is
http://www.pobox.com/~mph/   * its own reward.  -George Reamerstaff
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: complex crontab query

2003-09-30 Thread Kai Grossjohann
Matthew Hunt [EMAIL PROTECTED] writes:

 On Tue, Sep 30, 2003 at 10:56:20PM +0200, Kai Grossjohann wrote:

 My understanding is that putting more than one condition in it
 performs a logical conjunction.  So wouldn't it work to do like this?
 
 # minute hour dom month dow command
 031-7 * 4   mycommand

 I thought that might be the case, but the man page says:

 # Commands are executed by cron(8) when the minute, hour, and month of
 # year fields match the current time, and when at least one of the two
 # day fields (day of month, or day of week) matches the current time
 # (see ``Note'' below).

Ick.  Silly me.  Can't even read the manpage.

*blush*

Kai

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]