]> Pileus Git - ~andy/fetchmail/blob - contrib/maildaemon
Credit John Beck's fixes.
[~andy/fetchmail] / contrib / maildaemon
1 #!/bin/sh
2 #
3 # maildaemon, fetchmail driver intended to be invoked hourly by cron.
4 #
5 # Script by Larry Fahnoe <fahnoe@kegworks.mn.org>, who writes:
6 #
7 # This is intended to support a standalone system (NeXTSTEP in this case) 
8 # which makes manual, on-demand PPP connections to the outside world.  The
9 # script is run as the target user from cron on an hourly basis.  If it
10 # finds a PPP link is up (it sees routes on a PPP interface), fetchmail is
11 # invoked.  If the link is not up, and the hour is in the list of hours that
12 # connections should be made, the link is brought up and fetchmail is
13 # invoked.  The program or script used to bring up the link should return an
14 # exit status which reflects whether the link actually came up. 
15
16 # I wrote this because I wanted to be able to have control over the amount
17 # of time spent connected to an ISP and yet still be able to poll for mail
18 # at intervals that made sense to me.  One limitation of this script is that
19 # it does not take into account that an existing PPP link might be going to
20 # a different ISP or network.
21 #
22
23 # You'll have to configure these
24 USER=fahnoe                     # your name
25 HOME=/Users/fahnoe              # home directory (for the logfile)
26 FORCEHOURS="05 09 13 17"        # when to bring the link up if it's not already
27 SERVER=mailserver.isp.com       # mailserver host name
28
29 # Link initialization and wrapup scripts (you may have to configure these)
30 PPPUP="/usr/local/bin/pppup $SERVER"
31 PPPDOWN=/usr/local/bin/pppdown
32
33 PATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin:/usr/etc
34 export PATH USER HOME
35
36 LOG=$HOME/log/maildaemon.log
37
38 # get the mail, depends on $HOME/.fetchmailrc and $USER
39 FETCHMAIL( ) {
40     ( echo "`date` $SERVER"
41       fetchmail $SERVER
42       if [ $? -gt 1 ]
43       then
44           echo "`date` $SERVER (evil things happened in fetchmail)"
45       fi
46     ) >> $LOG 2>&1
47 }
48
49 # if the link is already up, check for mail.
50 # if the hour is in FORCEHOURS, force the link up and check for mail.
51 (netstat -rn | awk '{ print $6 }' | grep ppp[0-9] > /dev/null)
52 if [ $? -eq 0 ]
53 then
54     FETCHMAIL
55 else
56     hour=`date | sed -e 's/:/ /g' | awk '{ print $4 }'`
57     for x in $FORCEHOURS
58     do
59         if [ $hour = $x ]
60         then
61             $PPPUP
62             if [ $? -eq 0 ]
63             then
64                 FETCHMAIL
65                 $PPPDOWN
66             else
67                 echo "`date` $SERVER (link establishment failure)" >> $LOG
68                 exit 1
69             fi
70         fi
71     done
72 fi
73
74 exit
75