Como faço para mover o correio de / var / spool / mail / [user] para a caixa de correio dos usuários?

1

Eu preciso de um caminho (um script) para mover todas as últimas 100 mensagens do spool de correio de um usuário (/ var / spool / mail / theuser) para um arquivo / mbox no diretório de e-mail do usuário (/ home / theuser / mail). Existe uma maneira fácil de fazer isso?

    
por MyOnlyEye 02.03.2010 / 23:52

1 resposta

2

Aqui está uma rápida e suja vantagem inicial. Nenhuma verificação de erros e, na verdade, não "move" nada como está.

#!/usr/local/bin/bash
#
# DIRTY hack to append all but the last 100 messages from each file
# in a dir of mbox files to like named files in /tmp
#
# if an mbox has less than 101 messages, skip it
#
# requires formail (from the procmail installation..)

#
# we're writing in tmp - to write in the user's dir move this 
# inside the for loop and use $USERMAIL to write the base path
DESTDIR="/tmp"

for USERMAIL in 'ls -1'

do
MESSAGECOUNT='cat $USERMAIL | formail -q -s wc | wc -l | sed 's/^[ \t]*//''
COPYTHISMANY='expr $MESSAGECOUNT - 100'
if [ $COPYTHISMANY -gt 0 ]
then
echo "Copying $COPYTHISMANY messages from $USERMAIL to /tmp/$USERMAIL.allbutlast100"
cat $USERMAIL | formail -$COPYTHISMANY -s cat >> $DESTDIR/$USERMAIL.allbutlast100
# copy the last 100 to a new file
cat $USERMAIL | formail +$COPYTHISMANY -s cat >> $DESTDIR/$USERMAIL.last100
# to replace the original source mbox do something like
# mv /tmp/$USERMAIL.last100 $USERMAIL
fi
done
    
por 03.03.2010 / 04:28

Tags