#!/bin/sh
# ~jhs/bin/.sh/fetchmail.sh 		by Julian Stacey

# Bug: After an overnight ftp filled /usr I saw:
#	/home/jhs/.fetchmail.pid: File exists
#	At that point I also need to rm /home/mk/.fetchmail.pid

# Fetches mail from POP servers.
# Can be called manually.  Normall called by crontab. On gate Try crontab -e

# Sometimes the connection is down (eg @ 03:00 for security when 
# link not needed). No connection used to cause fetchmail (when called
# direct from crontab) to bleat, eg "fetchmail: Query status=2
# (SOCKET)", so this script does a ping first to check line is up.

# In case a mail server is down, I do a ping per host, to avoid
# a single ping fail preventing me downloading all hosts.

ping="/sbin/ping -q"
	# -q doesnt make it completely quiet,
	# I dont want it creating output that winds up as mail, 
	# so I need the redirect.
fetchm="/usr/local/bin/fetchmail -s -p POP3"
	# -p POP3	avoids error reports when it tries IMAP.

# Problem if route is down, stderr error warning goes to mail of mk

$ping -c 1 berklix.org > /dev/null && $fetchm

exit 0

