fetchmail-friends
[Top] [All Lists]

[fetchmail] Fetchmail and Webmin: a solution

2003-11-20 03:16:32
I posted the mail (below) a few days ago, but had no responses. In case
anyone else has a similar issue, this is my solution. I don't claim that
it is perfect, and I'm certainly open to improvements or suggestions,
but it works right now. There are some important assumptions:

- Each user has a home directory immediately under '/home'
- The name of the user directory is the same as the username

The following file is run every minute from a crontab entry for user
root. It looks for .fetchmailrc files in users' home directories, and,
when it finds one, it checks that that user has a fetchmail daemon
running. If that user does not have a fetchmail daemon running then one
is started.

==============================================
#!/bin/bash

for i in $(find /home -maxdepth 2 -name .fetchmailrc -print);
do
        USER=$(echo $i|awk -F / '{print $3}');
        if  ! (ps aux|grep [f]etchmail|grep ^$USER > /dev/null);
        then
                # need to kick off process
                echo "Starting fetchmail daemon for $USER at $(date)"
                su - $USER -c "/usr/bin/fetchmail -d 60"
        fi
done
==============================================

Hope this helps someone.
Keith

Original mail describing problem to be solved:

I've done some searching of the web and the mailing list archives but
been unable to find anything which helps. If I've missed something, I
apologise.

Situation: a Linux server running SMTP and IMAP servers, and using
Fetchmail to retrieve users' email. No interactive logins by users.
Webmin used by a few 'superusers' to create and manage each user's
.fetchmailrc.

Problem: How best to run fetchmail for each user.

Possibilities:

1. Have a crontab entry for each user which runs fetchmail once a
minute. Advantage: simple. Disadvantage: if email retrieval takes more
than a minute then fetchmail (rightly) complains that it is already
running. Observation: the fetchmail webmin module does not have an
interface to add daemon commands to a user's .fetchmailrc

2. Have a crontab job which builds a 'master' .fetchmailrc along the
lines of: for i in $(find /home -name .fetchmailrc); do cat $i
masterfile; done. Advantage: means one fetchmail process can run as a
daemon. Disadvantage: messy.

3. Discover an as-yet unfound 'include' directive in the .fetchmailrc
syntax so that I could check and dynamically build a master fetchmairc
file lines of the form 'include /home/john/.fetchmailrc

Any other ideas? I can't be the only person trying to set up such a
system, so I suspect I've missed something obvious.

Thanks,
Keith

<Prev in Thread] Current Thread [Next in Thread>
  • [fetchmail] Fetchmail and Webmin: a solution, Keith Edmunds <=