[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Mail loss!



Branden Robinson <branden@ecn.purdue.edu> writes:

> ssh -C roger.ecn.purdue.edu "mv $MAIL $HOME/mymail" && scp -C
> roger.ecn.purdue.edu:mymail /tmp && formail -s procmail < /tmp/mymail

As others have mentioned, you might want to use a lock to make sure
you don't corrupt the mail box if it's the one the system delivers to
actively.  Here I use the crufty script below to put my mailbox
somewhere I've told gnus to look for it.  This script properly handles
touchlocking too, but it depends on my lockfile-progs package which
should probably go away once dotlockfile supports all the needed
functionality.

#!/bin/bash

set +e
umask 077

CSHOST=stovepipe.cs.utexas.edu
MOVEMAIL=/lusr/gnu/libexec/emacs/20.3/i686-pc-linux-gnu/movemail
SSH="ssh"

${SSH} -P ${CSHOST} "[ -s mailbox -o -s mailbox.xfer ]"

if [ $? != 0 ]
then
  echo "get-mail: no mail"
  exit 0
fi

set -e

echo -n "get-mail: getting "
${SSH} -P ${CSHOST} \
  "if   [ -s mailbox.xfer ]; then egrep -c '^From ' mailbox.xfer; " \
  "elif [ -s mailbox ]; then egrep -c '^From ' mailbox; fi" \
    | tr -d '\n'
echo " message(s)"

if [ $? != 0 ]
then
  echo "get-mail: no mail"
  exit 0
fi

echo "get-mail: moving mail"
${SSH} -P ${CSHOST} \
  "[ -e mailbox.xfer ] || (umask 077; ${MOVEMAIL} mailbox mailbox.xfer)"

if [ $? != 0 ]
then
  echo "get-mail: ${SSH} -P failed"
  exit 1
fi

echo "get-mail: removing local tmp file"
rm -f /home/rlb/.gnus/mail/boxes/cs.tmp

if [ $? != 0 ]
then
  echo "get-mail: rm failed"
  exit 1
fi

echo "get-mail: fetching mailbox"

scp -C ${CSHOST}:mailbox.xfer /home/rlb/.gnus/mail/boxes/cs.tmp

if [ $? != 0 ]
then
  echo "get-mail: scp failed"
  exit 1
fi

echo "get-mail: appending to existing mailbox"
lockfile-create /home/rlb/.gnus/mail/boxes/cs
if [ $? != 0 ]
then
  echo "get-mail: BIG PROBLEM failed to lock mailbox for append"
  exit 1
fi

lockfile-touch /home/rlb/.gnus/mail/boxes/cs&
BADGER="$!"
cat /home/rlb/.gnus/mail/boxes/cs.tmp >> /home/rlb/.gnus/mail/boxes/cs
kill "${BADGER}" && true
lockfile-remove /home/rlb/.gnus/mail/boxes/cs

if [ $? != 0 ]
then
  echo "get-mail: cp failed"
  exit 1
fi

echo "get-mail: removing remote tmp file"
${SSH} -P ${CSHOST} rm -f mailbox.xfer

if [ $? != 0 ]
then
  echo "get-mail: remove of remote tmp file failed"
  exit 1
fi

exit 0

-- 
Rob Browning <rlb@cs.utexas.edu> PGP=E80E0D04F521A094 532B97F5D64E3930


Reply to: