[CentOS] Fetchmail question
R P Herrold
herrold at centos.org
Fri Dec 18 20:49:23 UTC 2009
On Fri, 18 Dec 2009, Stephen Harris wrote:
> You can always run multiple copies of fetchmail in the background if you
> want parallel fetching
or run just one tenth of those RC files (when well numbered)
present each time a script is invoked, if you are not in a
hurry to retrieve email from side accounts, and want to be
kind to the remote pop hosts
-- Russ herrold
#!/bin/sh
#
# ~/bin/get-stray-email.sh
# $Id: get-stray-fetchmail.sh,v 1.3 2009/10/23 13:48:47 herrold Exp herrold $
# License: GPLv3+
# bug reports to: info at owlriver.com
#
# use fetchmail with custom rc files, and pull
# upgrade to use a 0-9 rotor to spread load
#
export PATH='/usr/java/latest/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:~/bin/:/home/herrold/bin:~/bin/'
#
# the config files live in a protected directory
export FETCHRC=".fetchmail"
cd
[ ! -d $FETCHRC/ ] && {
mkdir $FETCHRC/
chmod 700 $FETCHRC
}
#
# defaults, and options parsing
# need to more into a while loop, and add a scan exit
QUIET="--silent "
DEBUG=""
[ "x$1" = "x-d" ] && {
export DEBUG="y "
shift 1
}
[ "x$1" = "x-v" ] && {
export QUIET=""
export VERBOSE="--verbose "
shift 1
}
[ "x${QUIET}" = "x" ] && {
export QUIET=""
export VERBOSE="--verbose "
}
#
# option $1 support being refactored; out for the moment
# Remembering Jimi ...
[ "xsix" = "x9" ] && {
#
# SUFFIX works when we cd into $FETCHRC and have the file naming set up
# right
SUFFIX=".fetchmailrc-gmail"
[ "x$1" != "x" ] && {
export SUFFIX=`echo ".fetchmailrc-gmail$1"`
# make sure we have one
[ ! -e ~/$FETCHRC/$SUFFIX ] && export SUFFIX=""
#
# actually we need to stop scanning options here
shift 1
}
}
#
# main body
# New model is to run a rotor
[ ! -e $FETCHRC/.fetch-rotor ] && touch $FETCHRC/.fetch-rotor
LASTRUN=` ( echo -n "0" ; cat $FETCHRC/.fetch-rotor | \
perl -p -e "tr/[0-9]//cd" ) `
[ "0$LASTRUN" -lt 1 ] && echo "00" > $FETCHRC/.fetch-rotor
LASTRUN=` ( ( cat $FETCHRC/.fetch-rotor | \
perl -p -e "tr/[0-9]//cd" ; echo " + 0" ) | bc ) `
[ "x${DEBUG}" != "x" ] && echo "Rotor is: $LASTRUN" 1>&2
#
# main loop
for i in ` ls -1 $FETCHRC/.fetchmailrc-*[0-9] | grep "${LASTRUN}$" `; do
[ "x${VERBOSE}" != "x" ] && {
echo "i: $i" 1>&2
}
[ -e ${i} ] && fetchmail -f ${i} -a ${QUIET} ${VERBOSE} || {
echo "Error: non-zero return code on: $i " 1>&2
grep -v "^#" $i | grep -v "[ ]" 1>&2
grep "user" $i 1>&2
}
sleep 3
# sleep 30
done
#
LASTRUN=` echo "${LASTRUN} + 1" | bc | rev | cut -c 1 | rev`
# echo "new LASTRUN: $LASTRUN"
echo "$LASTRUN" > $FETCHRC/.fetch-rotor
#
#
exit 0
#
#
# This is a sample ~/.fetchmail/.
cat - << END > /dev/null
#
# gmail pop works
# sample fetchmail -f config file
poll pop.gmail.com with proto pop3:
port 995
timeout 60
user "GMAILUSERID at gmail.com" there with
password "GMAILPASSWORD"
is LOCALUSERID here
fetchall
expunge 50
options ssl
#
END
#
-------------- next part --------------
A non-text attachment was scrubbed...
Name: get-stray-fetchmail.sh
Type: application/x-sh
Size: 2471 bytes
Desc:
URL: <http://lists.centos.org/pipermail/centos/attachments/20091218/6526c007/attachment.sh>
More information about the CentOS
mailing list