On 2000.07.26, in <[EMAIL PROTECTED]>, "Gregor Zattler" <[EMAIL PROTECTED]> wrote: > > * David Champion <[EMAIL PROTECTED]> [Mit 26 Jul 2000 03:37:59 GMT]: > > I have procmail deliver to ~/Mail/lists/listname. Each "listname" in > > that directory is a symlink to ~/Mail/lists/monthly/listname-YYYYMM or > > to ~/Mail/lists/annual/listname-YYYY. A cron job rewrites the symlinks > > once a month using a Makefile designed for handling the links. > > I'm interested too. I know it's OT on this list but perhaps it's > easier to post it on the list. There were a number of people interested, so I guess I will. I cleaned & commented it up a bit, too, and added an ability to do quarterlies since Mikko mentioned that. It's not hard to define whatever period you want. I hope everything still works. :) I feel a little foolish -- there's really no reason this should be a makefile instead of a shell script. But my old archive handler (using another scheme) used make with good reason, so it came naturally in this case. Oh well. I'll add to what Mikko mentioned before: using symlinks is nice, too, because it takes a lot of weight from procmail. Using symlinks is essentially caching the "date" command output on the filesystem, and executing it once per month rather than with each incoming message. It's altogether more efficient. Enough of that. Here's the file. -- -D. [EMAIL PROTECTED] NSIT University of Chicago
## ## Makefile for managing periodic mail-archive symlinks ## ## $Id: Makefile,v 1.2 2000/07/27 10:16:23 dgc Exp $ ## ## DIRECTIONS: ## 1. Drop this Makefile into a directory where you want to keep links to ## your archives. ## 2. Create subdirectories there named "annual", "monthly", and/or ## "quarterly", or whatever you'd rather call them. ## 3. For each archive: ## a. Decide whether you want to cycle the archive on an annual, ## quarterly, or monthly basis. ## b. Run "make add ARCHIVE=name-of-archive PERIOD=xxx", where "xxx" is ## the period you decide on. This will create the initial symlink. ## 4. Set up procmail to deliver mail into the "name-of-archive" folder. ## 5. Create a cron(1) task to run "cd .../path/to/dir; make rotate" once ## per month. This will update all symlinks. (Actually, you can run ## this more or less often; it doesn't matter. If you made a weekly ## period, you could run it monthly *and* weekly.) ## ## NOTES: ## The file for the "family" archive (cycled monthly) for April, 1998 ## will be .../monthly/family-199804. You can gzip these if you wish -- ## no trouble. ## ## To add support for a new period, create a subdirectory for it, and ## add a macro definition for SFXfoo as below. SFXfoo should expand ## to the correct suffix for today's date, and be unique among all ## iterations of that period. For example, a period of one week, labelled ## according to the ISO definition, could use ## SFXweekly = `date %Y-%V` ## ## You can change SFX* macros as you wish if you don't like these formats, ## but be sure to change $(STRIP) accordingly. $(STRIP) must be capable ## of removing any of your SFX* macros from the end of a filename. ## ## Uncomment to debug, or use "make DO=echo". #DO = echo ## Default period for rotation of new archives with "make add-archive". ## Supercede this with (for example) "make add-archive PERIOD=quarterly". ## A valid PERIOD = monthly ##### You probably don't need to touch anything else. ##### ## Generates a suffix for PERIOD=annual SFXannual = `date +%Y` ## Generates a suffix for PERIOD=monthly SFXmonthly = `date +%Y%m` ## Generates a suffix for PERIOD=quarterly, like "1997q2". (Hi Mikko! :) SFXquarterly = `date '+[%Yq] P %m 1 - 3 / 1 + p' | dc` ## A command to strip suffices from archive files. STRIP = sed -e 's/-[0-9][0-9][0-9][0-9q-]*$$//' -e 's/-[0-9][0-9][0-9][0-9q-]*\.gz$$//' ## How to create and remove locks. LOCK = /opt/bin/lockfile UNLOCK = /usr/bin/rm -f ## A default target that tells you available targets. all: @echo @echo "make rotate - rotate all archives" @echo "make add ARCHIVE=name [PERIOD=xxx] - link new archive (default period=$(PERIOD))" @echo @echo "or, if you prefer:" @echo "make add-annual ARCHIVE=name - link new archive (annual period)" @echo "make add-monthly ARCHIVE=name - link new archive (monthly period)" @echo "make add-quarterly ARCHIVE=name - link new archive (quarterly period)" @echo ## Safety valves check-archive: @ if [ -z "$(ARCHIVE)" ]; then \ echo; \ echo '!!! You need to give ARCHIVE=name on the command line.'; \ echo; \ exit 255; \ fi check-period: @ if [ -z "$(PERIOD)" ]; then \ echo; \ echo '!!! PERIOD is not set.'; \ echo; \ exit 255; \ fi ## Add an archive using default period. add: @ $(MAKE) add-any PERIOD=$(PERIOD) ARCHIVE=$(ARCHIVE) DO=$(DO) ## Add archives with explicit period. add-annual: @ $(MAKE) add-any PERIOD=annual ARCHIVE=$(ARCHIVE) DO=$(DO) add-monthly: @ $(MAKE) add-any PERIOD=monthly ARCHIVE=$(ARCHIVE) DO=$(DO) add-quarterly: @ $(MAKE) add-any PERIOD=quarterly ARCHIVE=$(ARCHIVE) DO=$(DO) ## A target that's always made but never up to date. always: ## Add an archive add-any: check-period check-archive @ if [ -f $(ARCHIVE) ]; then \ $(DO) mv $(ARCHIVE) $(PERIOD)/$(ARCHIVE)-$(SFX$(PERIOD)); \ fi; \ $(DO) ln -s $(PERIOD)/$(ARCHIVE)-$(SFX$(PERIOD)) $(ARCHIVE) rotate: @ $(MAKE) rotate-annual PERIOD=annual ARCHIVE=$(ARCHIVE) DO=$(DO) @ $(MAKE) rotate-monthly PERIOD=monthly ARCHIVE=$(ARCHIVE) DO=$(DO) @ $(MAKE) rotate-quarterly PERIOD=quarterly ARCHIVE=$(ARCHIVE) DO=$(DO) rotate-$(PERIOD): rotate-any rotate-any: always check-period /bin/ls $(PERIOD)/$(ARCHIVE)* 2>/dev/null \ | sed -e 's#.*/##' \ | $(STRIP) \ | uniq \ | while read archive; do \ $(DO) $(LOCK) $$archive.lock; \ $(DO) rm -f $$archive; \ $(DO) ln -s $(PERIOD)/$$archive-$(SFX$(PERIOD)) $$archive; \ $(DO) $(UNLOCK) $$archive.lock; \ done