[fetchmail]fetchmail's last run

Paul Dickson paul@permanentmail.com
Tue, 29 Mar 2005 07:20:16 -0700


This is a multi-part message in MIME format.

--Multipart=_Tue__29_Mar_2005_07_20_16_-0700_/QgmWPiTlGtvoPZb
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Mon, 28 Mar 2005 03:55:44 -0500, Payal Rathod wrote:

> Hi,
> I have fetchmail running every 20 mins. Sometimes due to bad link or 
> a big mail stuck in queue, fetchmail does not work. This is not a 
> problem when I am around. But in my absence my boss would need to 
> know when was the last time fetchmail ran successfully. Can fetchmail 
> trigger an event like sending a mail or updating a (internal) webpage 
> to give the time and day etc after a successful run? Or is there any 
> other possible solution?

I run/monitor fetchmail with the attached script.  The output looks like:

Tue Mar 29 05:35:00 MST 2005
paul@pop.west.cox.net: 14 messages (66536 octets)
nancy@pop.west.cox.net: 1 message (13134 octets)
Tue Mar 29 05:50:00 MST 2005
paul@pop.west.cox.net: 17 messages (144311 octets)
Tue Mar 29 05:56:00 MST 2005
paul@pop.west.cox.net: 6 messages (26868 octets)
Tue Mar 29 06:06:55 MST 2005
paul@pop.west.cox.net: 12 messages (76880 octets)
Tue Mar 29 06:08:00 MST 2005
paul@pop.west.cox.net: 4 messages (15677 octets)
Tue Mar 29 06:08:27 MST 2005
Tue Mar 29 06:09:23 MST 2005
paul@pop.west.cox.net: 1 message (5463 octets)

If multiple times appear without downloaded E-mail, then a problem is
very likely.

Because of the "--expunge 50" argument, totals aren't accurate when more
than 50 messages/mailbox are downloaded.

	-Paul


--Multipart=_Tue__29_Mar_2005_07_20_16_-0700_/QgmWPiTlGtvoPZb
Content-Type: text/plain;
 name="fetchit"
Content-Disposition: attachment;
 filename="fetchit"
Content-Transfer-Encoding: 7bit

#! /bin/sh
LOCKFILE=~/fetchit.$USER.lock

FETCHMAILRC=
if [ "$1" = "others" ]; then
  FETCHMAILRC="--fetchmailrc /home/dickson/.fetchmailrc2"
fi

if [ -f $LOCKFILE ]; then
  exit
fi

>~/fetch.errors

echo `date` >>~/fetch.log
fetchmail $FETCHMAILRC --all --expunge 50 -L ~/fetch-log 2>&1 \
  | tee ~/fetch.errors \
    | grep -E ".*message.*for " \
      | sed -n -e 's/\(fetchmail: \)\([0-9]\+ messages*\)\( for \)\(.*\)\( at \)\(.*\)\( \)\((.*)\)\./\4@\6: \2 \8/p' >>~/fetch.log

if [ -f $LOCKFILE ]; then
  rm $LOCKFILE
fi

--Multipart=_Tue__29_Mar_2005_07_20_16_-0700_/QgmWPiTlGtvoPZb--