aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/maildaemon
blob: 3728c333054786ffcd5a9e7873af7a463f720cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
#
# maildaemon, fetchmail driver intended to be invoked hourly by cron.
#
# Script by Larry Fahnoe <fahnoe@kegworks.mn.org>, who writes:
#
# This is intended to support a standalone system (NeXTSTEP in this case) 
# which makes manual, on-demand PPP connections to the outside world.  The
# script is run as the target user from cron on an hourly basis.  If it
# finds a PPP link is up (it sees routes on a PPP interface), fetchmail is
# invoked.  If the link is not up, and the hour is in the list of hours that
# connections should be made, the link is brought up and fetchmail is
# invoked.  The program or script used to bring up the link should return an
# exit status which reflects whether the link actually came up. 
# 
# I wrote this because I wanted to be able to have control over the amount
# of time spent connected to an ISP and yet still be able to poll for mail
# at intervals that made sense to me.  One limitation of this script is that
# it does not take into account that an existing PPP link might be going to
# a different ISP or network.
#

# You'll have to configure these
USER=fahnoe			# your name
HOME=/Users/fahnoe		# home directory (for the logfile)
FORCEHOURS="05 09 13 17"	# when to bring the link up if it's not already
SERVER=mailserver.isp.com	# mailserver host name

# Link initialization and wrapup scripts (you may have to configure these)
PPPUP="/usr/local/bin/pppup $SERVER"
PPPDOWN=/usr/local/bin/pppdown

PATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin:/usr/etc
export PATH USER HOME

LOG=$HOME/log/maildaemon.log

# get the mail, depends on $HOME/.fetchmailrc and $USER
FETCHMAIL( ) {
    ( echo "`date` $SERVER"
      fetchmail $SERVER
      if [ $? -gt 1 ]
      then
          echo "`date` $SERVER (evil things happened in fetchmail)"
      fi
    ) >> $LOG 2>&1
}

# if the link is already up, check for mail.
# if the hour is in FORCEHOURS, force the link up and check for mail.
(netstat -rn | awk '{ print $6 }' | grep ppp[0-9] > /dev/null)
if [ $? -eq 0 ]
then
    FETCHMAIL
else
    hour=`date | sed -e 's/:/ /g' | awk '{ print $4 }'`
    for x in $FORCEHOURS
    do
        if [ $hour = $x ]
        then
            $PPPUP
            if [ $? -eq 0 ]
            then
                FETCHMAIL
                $PPPDOWN
            else
                echo "`date` $SERVER (link establishment failure)" >> $LOG
                exit 1
            fi
        fi
    done
fi

exit
</varlistentry> <varlistentry> <term>Entered-Date:</term> <listitem> <para>LSM-generation time in YYYY-MM-DD format.</para> </listitem> </varlistentry> <varlistentry> <term>Description:</term> <listitem> <para>Taken straight from the RPM Description field.</para> </listitem> </varlistentry> <varlistentry> <term>Keywords:</term> <listitem> <para>Taken from the value of the <option>-k</option> command-line option. If no such option is given, it is omitted.</para> </listitem> </varlistentry> <varlistentry> <term>Author:</term> <listitem> <para>Taken from the value of the <option>-a</option> command-line option. If no such option is given, it looks for an AUTHORS file in the current directory (GNU convention) and uses that. If no AUTHORS file is present, your email addess and full name from the password file</para> </listitem> </varlistentry> <varlistentry> <term>Maintained-By:</term> <listitem> <para>Taken from the value of the <option>-m</option> command-line option. If that was not given, taken from the RPM Packager field. If that was not given, fill in the Author name.</para> </listitem> </varlistentry> <varlistentry> <term>Primary-Site:</term> <listitem> <para>The first (site) line is taken from the RPM URL field. Second and subsequent lines list tarballs and RPMs that match on name, version number, and release number with the RPM algument. For each file, size in 1K blocks is filled in. </para> </listitem> </varlistentry> <varlistentry> <term>Alternate-Site:</term> <listitem> <para>This field is not generated.</para> </listitem> </varlistentry> <varlistentry> <term>Original-Site:</term> <listitem> <para>This field is not generated.</para> </listitem> </varlistentry> <varlistentry> <term>Platforms:</term> <listitem> <para>Taken from the value of the <option>-p</option> command-line option. If no such option is given, 'All' is filled in.</para> </listitem> </varlistentry> <varlistentry> <term>Copying-Policy:</term> <listitem> <para>Taken straight from the RPM License field.</para> </listitem> </varlistentry> </variablelist> <para>These are all the fields supported in LSM version 3. You can see the <ulink url='http://ibiblio.org/pub/Linux/LSM-TEMPLATE'> LSM template </ulink> for full details.</para> </refsect1> <refsect1 id='author'><title>AUTHOR</title> <para>Eric S. Raymond <email>esr@thyrsus.com</email>. For updates, see <ulink url="http://www.catb.org/~esr/software.html"> http://www.catb.org/~esr/software.html</ulink>.</para> </refsect1> <refsect1 id='see_also'><title>SEE ALSO</title> <para><citerefentry><refentrytitle>rpm</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> </refsect1> </refentry>