Re: massive fetchmail frustration
Britton wrote:
>...
>Lastly, does anyone have a clean way set up to invoke fetchmail as root
>and get mail for all users? I would like to see that also.
This is my setup: I use fetchmail as a cron job to download mail and I
pass it to procmail to distribute to users. I use sendmail.
There is a script `poll.mail' to establish the dial-up connection and
download mail; this has to be run as superuser. The only problem I have
with it is that if I become superuser from another account than my own,
a lot of the list mail for me ends up in that other user's mailbox. I
don't know why this is. I also use this script to collect news for the
groups I am interested in and download it to my local server.
poll.mail is run by cron, as root. As superuser, run `crontab -e' and add
this line:
2 4 * * * /usr/local/bin/poll.mail
Alternatively, edit /etc/crontab; you have to add the root user name:
2 4 * * * root /usr/local/bin/poll.mail
This runs the job at 4.02am every day. (I run it more often.)
The fetchmail configuration is in /root/.fetchmail1rc, and is readable
only by root. (This is required by fetchmail if it is running as root.)
It says:
poll mail.enterprise.net protocol pop3 username xxxxx password yyyyy smtphost localhost
Mail is held by the ISP for user xxxxx [not really!] and /etc/aliases
makes this go through procmail:
# enterprise mail name
xxxxx: "| /usr/bin/procmail -f -"
Procmail configuration is in /etc/procmailrc. How well it works depends on
how tightly you can define email addresses. The main problem comes from the
wide variety of ways in which mailing lists forward messages.
#! /bin/bash
# Poll for mail
# May be run either by cron or at will by the superuser.
PATH=/bin:/usr/bin:/etc:/sbin:/usr/sbin:/usr/local/bin
# See if we already have PPP running
if netstat -nr | grep ' ppp' >/dev/null
then
echo PPP already running
ppp_running=TRUE
else
# if not, start it up...
if [ -f /var/run/diald.pid ] && ps -p `cat /var/run/diald.pid`
then
echo diald is running
ping -c 1 mail.enterprise.net
ppp_running=TRUE
else
ppp_running=FALSE
/usr/local/bin/ppp-on
fi
sleep 2
waitpd=0
until netstat -nr | grep ' ppp' >/dev/null
do
if ps -axu | grep -v grep | grep -E 'pppd|diald' >/dev/null
then
sleep 5
waitpd=`expr $waitpd + 5`
if [ $waitpd -gt 120 ]
then
echo Timed out
exit 2
fi
else
echo PPP session was not established
exit 1
fi
done
fi
sleep 5
# Collect any mail that is waiting for us
echo "Calling for mail for lfix.co.uk"
fetchmail -aF -f /root/.fetchmail1rc
case $? in 0) :;; # no problem
1) echo No mail to collect;;
2) echo Could not open socket;;
3) echo User authentication failed;;
4) echo Fatal protocol error;;
5) echo syntax error in fetchmail command;;
6) echo Bad permissions for run control file;;
7) echo Server error reported, or time-out;;
8) echo Exclusion error - is another fetchmail running\?;;
9) echo Server reported \'Lock busy\';;
10) echo SMTP failure;;
11) echo Internal error;;
*) echo Totally unexpected error in fetchmail;;
esac
# Send anything we have for the outside world
sendmail -q &
# Get news
/usr/local/bin/slurp -d news.enterprise.net
# If we started PPP, stop it again
if [ "$ppp_running" = FALSE ]
then
/usr/local/bin/ppp-off
fi
DEFAULT=olly
LOGFILE=/var/log/procmail.log
:0
* ^TO.*Daniel.Elphick@lfix.co.uk
!dan
:0
* ^TO.*dan@lfix.co.uk
!dan
#
:0E
* ^TO.*Ruth.Elphick@lfix.co.uk
!ruth
:0E
* ^TO.*ruth.*@lfix.co.uk
!ruth
#
:0E
* ^TO.*Abigail.Elphick@lfix.co.uk
!abby
:0E
* ^TO.*abby@lfix.co.uk
!abby
#
:0E
* ^TO.*Hannah.Elphick*@lfix.co.uk
!hannah
:0E
* ^TO.*hannah@lfix.co.uk
!hannah
#
:0E
* ^TO.*Nicholas.Elphick@lfix.co.uk
!nick
:0E
* ^TO.*nick@lfix.co.uk
!nick
#
:0E
* ^TO.*Thomas.Elphick@lfix.co.uk
!tom
:0E
* ^TO.*tom@lfix.co.uk
!tom
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
Reply to: