procmail
[Top] [All Lists]

help with 'lockfile' in shell script

1997-12-06 23:52:50

Ok, my scenario is a little atypical, so here's the setup information:

- Mailboxes on my system are delivered using '|appnmail MBNAME' rather than  
just MBNAME

- no lockfiles are needed for normal delivery since appnmail does its own 
locking

- I use a global lockfile for delivery
LOCKFILE=${HOME}/.procmail/global-procmail.lock

- I use a program called 'compactmail' to delete messages more than 3 days  
old in my backups mailbox.

Although this 'compactmail' takes only seconds to run, it can be at the same  
time that new mail is being delivered to my backups mailbox.

In my nightly cron file I have this:

#!/bin/sh

/usr/local/bin/compactmail -u -d 3 Backups

exit 0


How can I setup procmail and this shell script to make sure that it waits  
for 'compactmail' to finish before delivering new mail?

I thought about this:

#!/bin/sh

LOCKFILE=${HOME}/.procmail/global-procmail.lock

while [ -r $LOCKFILE ]; do
        sleep 5
done

touch $LOCKFILE
/usr/local/bin/compactmail -u -d 3 Backups
/bin/rm -f $LOCKFILE

exit 0

But what happens if mail comes in right between the 'done' and the 'touch'  
lines?  I realize it's a longshot....

Basically: is there a better way?

Thanks

TjL


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