linux-l: fetchmail per crond automatisieren
Volker Mueller
volker.mueller at gmx.de
Sa Jan 1 21:35:02 CET 2000
On Sat, 1 Jan 2000, Bjoern Gerhart wrote:
>Was bedeuten denn die beiden &? Soweit ich weiß, bedeutet ein &,
>daß der Befehl im Hintergrund ausgeführt wird..
>
>Mein Problem ist, daß der Server erst auflegen soll, wenn alle
>Mails abgeholt sind.
ich mach' das so:
in /etc/ppp/ip-up:
[...]
#################################################################
# Add here (between "touch /tmp/trans_active" and "wait")
# the things to be done while we're online
touch /tmp/trans_active
#---vvv
date=$(date)
/usr/sbin/sendmail -q &
echo -n "------ $date ------ " >> /home/volker/fetchmail.log
su - volker -c "/usr/bin/fetchmail -a -v >> \
/home/volker/fetchmail.log 2>&1" &
echo -n "------ $date ------ " >> /home/volker/dnetc.log
su - volker -c "/home/volker/dnetc/dnetc -update >> \
/home/volker/dnetc.log 2>&1" &
/usr/sbin/sendmail -q &
#---^^^
wait
rm -f /tmp/trans_active
#################################################################
[...]
und dann mit /etc/ppp/movemail:
#!/bin/bash
#set -x
lockfile=/tmp/trans_active # lockfile created from /etc/ppp/ip-up
maxtime=900 # MUST be defined in seconds!
interval=2s # Interval to check for existing $lockfile
date=$(date)
echo ------ $date ------
starttime=$(date +%s)
/sbin/init.d/diald start&
while [ $(ping -c1 130.149.4.10 2>&1 | grep -c " 0% packet loss") != 1 ]; do
: # nothing
done
timediff=0;
while test $timediff -lt $maxtime; do
nowtime=$(date +%s)
timediff=$(($nowtime - $starttime))
if ! test -e $lockfile ; then
echo "No lockfile ($lockfile) from /etc/ppp/ip-up. Finishing the job after"
echo appr. "$timediff seconds. (Hopefully correct ...)"
/sbin/init.d/diald stop
echo "... and killing myself (PID: $$)."
kill $$
fi
sleep $interval;
done
echo "$0 canceled because maxtime ($maxtime) is reached."
echo "Removing lockfile ($lockfile)."
rm -f $lockfile
echo
/sbin/init.d/diald stop
exit 1
die Mails abholen. Mit dem Lockfile aus ip-up laesst sich auch der
Verbindungsabbruch (ip-down) etwas genauer steuern ...
Tschau, Volker
--
<ESC>:r .signature
mailto:volker.mueller at gmx.de | http://www.in-berlin.de/user/flinux
:wq
Mehr Informationen über die Mailingliste linux-l