On Wed, Sep 23, 2009 at 04:50:56PM +0200, Ionel Mugurel Ciobica wrote: > On 23-09-2009, at 15h 21'53", Chris G wrote about "Re: How to remove empty > maildir?" > > > > > There's no atomic way of checking if all three sub-directories are > > empty so, in the general case, some other process may come along > > and put something in one of the sub-directories after you have > > checked it but before you do the removal. > > Not if you rename them before you do the check (not tested): > The the 'other' application will either recreate them or fall in a heap, neither of which is particularly helpful.
> for A in all-mailboxes ; do > cd $A > mv new new-$$ > mv tmp tmp-$$ > mv cur cur-$$ > if [ `find ???-$$ -type f | wc -l` -eq '0' ]; then > if [ -e new ] && [ -e tmp ] && [ -e cur ] ; then > echo "$A was empty but just right now some e-mail arrived." > rmdir ???-$$ > else > echo "$A is empty." > rm -fr ../$A > echo "Ups, $A was empty! Now is gone..." > fi > else > echo "$A has mail." > mv new-$$ new > mv tmp-$$ tmp > mv cur-$$ cur > fi > done > > > > You can also turn off $sendmail when you do the check :-)) > I doubt if it's just sendmail you need to turn off. -- Chris Green