procmail
[Top] [All Lists]

firing a daily maintenance routine

1997-07-10 16:35:00
Dallman Ross wrote about his and my long-ago discussion of using procmail to
trigger once-a-day jobs on a system where the user has no cron access,

| I would (and do) use a more low-overhead way to check the date.  One way
| discussed here in the past (by era, dattier, etc.) is to look at the
| time-stamp on the incoming message and parse it for the new date.  (Once
| you know the date has changed, *then* run your perl script.)

What has worked for me recently is (it has the overhead of ls, but not that
of perl) to compare the date in the From_ line to that in the mod time of my
procmail logfile.  If they differ, this must be the first incoming letter of
a new day and it's time to start a new logfile.

To make sure that reprocessing old mail through procmail doesn't confuse
the recipe, it checks first to make sure that it was called from .forward
(my .forward pipes to "| ... /path/to/procmail -f- DOTFWD=yes"; the DOTFWD
variable thus is unset when I call procmail interactively or from a cron
job [though of course, we're talking here about a site where I have no cron
access anyway] but equal to "yes" for mail that is just arriving).

An even cheaper way (it would require one shell per day and no ls, date, or
perl with every single incoming letter) unless you're choked for space in
your disk quota might be to keep the date stamp in another file and read it
in with an INCLUDERC, something like this:

   :0
   * DOTFWD ?? yes
   {
    LOCKFILE=.today.lock
    INCLUDERC=.today

# .today contains    TODAY='Mmm dd'
# or TODAY='dd Mmm' or however the date and month appear in your From_ lines

    :0 # tailor to format of your From_ lines
    * $ ! ^^From [^ ]+ +[^ ]+ $TODAY( )
    {
     :0ci # also W if applicable
     | master_script_for_invoking_daily_maintenance_work

     :0aic # again, tailor to format of your From_ lines
     * ^^From .* +... +\/... ..
     | echo "TODAY='$MATCH'" > .today # regional lockfile is still in effect
    }

    LOCKFILE
   }

By including "TODAY=" in the .today file we can read it in with INCLUDERC
and not need to invoke cat for every incoming letter.

The reasons I check the month as well as the day are that (1) in case I
ever invert the logic (and compare the From_ date to the stored one rather
than vice versa) *and* I mess up the delimiters, I won't get a false match
on the first day after a thirty-one day month just because "1" appears in
"31", (2) I might mess up the delimiters and yesterday's date of the month
might match the hour, minute, or second of this letter's timestamp, again
giving a false match, and  . . . 

(3) before the days of spam I considered the possibility of not getting email
for exactly a month.  Nowadays one could get by with checking just the day of
the week.

<Prev in Thread] Current Thread [Next in Thread>