> On Tuesday 29 October 96, at 14 h 0, the keyboard of
gilles(_at_)mc2(_dot_)fr
> (Gilles GOULLET) wrote:
>
> > I just want to make some of my recipes being taken in account
only
> > during certain periods, typically at business hours.
>
> date(1) offers a lot of options to retrieve date and time.
>
> > So the recipe "put personal mail in the appropriate folder"
would
> > have to become "put personal mail in appropriate folder if business
hours".
>
> Beware with the following recipes: date and test are likely to have
> different options according to the Unix you use (I use only GNU tools so
> I'm safe and portable).
>
> DAY=`date +'%a'`
> HOUR=`date +'%k'`
>
> # Put personal mail in /tmp/personal if business hours
> :0
> * TO.*some_address
> * ? test ( $HOUR -le 17 ) -a ( $HOUR -ge 9 ) \
> -a ( $DAY != "Sat" ) -a ( $DAY != "Sun" )
> /tmp/personal
1. That "test" command above will fail unless the parens are quoted.
2. I use the "standard" SysV date, which is already installed on most
systems. I would use GNU date, but its arguments are arbitrarily
different, for no good reason. It would be great if GNU date has
compatible arguments -- that way, may scripts would continue working
with it. But it doesn't -- so sad.
If you expect to have several recipes depending upon this test, set a
variable for later usage.
DAY=`date +%w` # day of week, Sun=0
HOUR=`date +%H` # hours of the date, 00-23
MINS=`date +%M` # minute of the hour, 00-59
:0 # round up the hour
* ? test $MINS -gt 0
{ HOUR=`expr $HOUR + 1` }
# performing a modulo 24 is not necessary here, since for our
# purposes 24 == 0 in the test below.
:0 # business ours are 8-5am M-F
* ? test \( $HOUR -ge 8 \) -a \( $HOUR -le 17 \)
{ BUSINESS_HOURS=1 }
Then, at various places in your .procmailrc or any included recipe
files, you can reference "BUSINESS_HOURS" like this:
:0
* BUSINESS_HOURS ?? .
* ^TO_(some_address)
/tmp/personal
Another example: if you are not at work, you might not want to have
"root" mail clogging up your inbox:
:0 # if not at work, and it is sysadmin stuff
* ^TO_(root|mailer-daemon|postmaster)
* !BUSINESS_HOURS ?? .
/tmp/rootmail