Karl Vogel <vogelke(_at_)c17mis(_dot_)wpafb(_dot_)af(_dot_)mil> writes:
...
% cp /var/mail/vogelke /tmp/inbox
% lockfile -ml
% cp /dev/null /var/mail/vogelke
% lockfile -mu
Danger, danger! You can lose mail doing this. In particular, if mail is
delivered after the first copy, but before you lock the mailbox, you lose.
You should lock the mailbox before the cp:
% lockfile -ml
% cp $MAIL /tmp/mymail
% cp /dev/null $MAIL
% lockfile -mu
Philip Guenther
----------------------------------------------------------------
Philip Guenther UNIX Systems and Network Administrator
Internet: guenther(_at_)gac(_dot_)edu Phonenet: (507) 933-7596
Gustavus Adolphus College St. Peter, MN 56082-1498
I am _not_ a representative sample of the Gustavus Community. Yeah, right...
Source code never lies (it just misleads). (Programming by Purloined Letter?)