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

Re: fetchmail at boot



On Sat, 7 Jul 2001 01:59:06 -0500
xucaen@yahoo.com wrote:

> currently I have fetchmail being run at login from ~/.bash_profile.
> this is fine for myself at login, however, I would like to have
> fetchmail run as a daemon at boot time so it can poll for multiple
> users. Where should I have fetchmail loaded from to do this?

This is exactly what I do.

Fetchmail needs to run as root so you need a .fetchmailrc in /root like
this:

set daemon 600
poll pop.xxx.xxx
protocol pop3
username gsmh@gmx.co.uk to gsmh@scgf.gmx.co.uk
password xxxxxxx
poll pop.xxxxx.xxxxx
protocol pop3
username scgf01 to gsmh@scgf.gmx.co.uk
password xxxxxxx
poll pop.xxxxxx.xxxxxx
protocol pop3
username scgf02 to gsmh@scgf.gmx.co.uk
password xxxxxxx

As you can see, I poll three mailboxes. The daemon 600 ensures that
fetchmail runs as a daemon and polls the mailboxes at intervals of 10
minutes. I have a cable connection to the internet so this works well.

All you need to do is start fetchmail during bootup:

#! /bin/sh
# /etc/init.d/fetchmail
# Hacked by Ross Boylan from the exim script which was...
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for exim by Tim Cutts <timc@chiark.greenend.org.uk>
# To start fetchmail as a system service, copy this file to
# /etc/init.d/fetchmail and run "update-rc.d fetchmail
# defaults".  A fetchmailrc file containg hosts and
# passwords for all local users should be placed in /root
# and should contain a line of the form "set daemon <nnn>".
#
# To remove the service, delete /etc/init.d/fetchmail and run
# "update-rc.d fetchmail remove".

set -e


DAEMON=/usr/bin/fetchmail
ARGS="--fetchmailrc /root/.fetchmailrc"
DEBUGLOG=/var/log/fetchmail.log
NAME=fetchmail

echo `whoami` `date` >> $DEBUGLOG
# This was not my only test of uid.  I created a shell script and
# ran it from start-stop-deamon. The script printed whoami as root.

test -x $DAEMON || exit 0 

case "$1" in
  start)
    echo -n "Starting fetchmail: "
    start-stop-daemon --start -v --exec $DAEMON -- $ARGS >> $DEBUGLOG
        # Note the use of -- before args to the program
    echo "Done."
    ;;
  stop)
    echo -n "Stopping fetchmail: "
    start-stop-daemon --stop --oknodo --exec $DAEMON
    echo "Done."
      ;;
  restart|reload|force-reload)
    echo "Restarting fetchmail: "
    start-stop-daemon --stop --oknodo --exec $DAEMON
    start-stop-daemon --start -v --exec $DAEMON -- $ARGS >> $DEBUGLOG
    echo "Done."
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart}"
    exit 1
    ;;
esac

exit 0


I also have a .forward file in my home directory which sorts mail for
other users:

# Exim filter  <<== do not edit or remove this line!

if error_message then finish endif
logfile $home/eximfilter.log

	if $h_To: contains "scott@gmx.co.uk" 
	then deliver scott

	elif $h_To: contains "sah1"
	then deliver scott

	endif

'scott; is obviously a user on my system. Not sure why I have this file in
*my* home directory, but it works so I just leave it there. I assume it
works because in my .fetchmailrc I am telling fetchmail to send all mail
initially to me as gsmh, therefore mail becomes my property before exim
takes over to filter it.

All credit to those who originally supplied me with this info.

Hope this helps.

-- 
Phillip Deackes
Using Progeny Debian Linux



Reply to: