Hi out there!
Now _I_ am the one that got stuck writing a shell script.
Background:
I am subscribed to linux-kernel and that generates a massive amount of
email-traffic. I live in Germany, where Internet via modem or ISDN is
_expensive_. I use fetchmail to get my mail from a pop3-host called
'mail'. I have access to machines in the local ethernet of 'mail'.
What I want to do:
Write a script that runs fetchmail on a box that is connected to 'mail'
via ethernet, compress (bzip2) the mail in /var/spool/mail/$USER as it
comes down the line and send it over the modem line to my home box,
where it is decompressed and simply appended to /var/spool/mail/$USER.
What I have come up with so far:
...is the following script:
--begin script--
#!/bin/bash
# if you install this script as get_fast_mail
# on a fast inet-access box,
# you can decrease fetchmail time by up to 90%!
# simply install this script in your local bin/ on the
# fast access box and issue the following command when
# you wish to download mails:
# ssh fastboxname get_fast_mail
# ssh fastboxname 'cat /tmp/bzipped-mails' | bunzip2 >
/var/spool/mail/$USER
# some filenames
MAILSPOOL=/var/spool/mail
MAILFILE="$MAILSPOOLDIR/$USER"
FIFONAME="/tmp/mail.bzipped"
# check that the necessary files are in place
# and create them if needed
[ -f "$MAILFILE" ] || touch "$MAILFILE" || echo ... && exit 1
[ -p "$FIFONAME" ] || mknod $FIFONAME p || echo ... && exit 1
# start the mailfile-scanning tail command.
# It will die automagically when we delete $MAILFILE later on...
# (--follow=name option),
# Pipe the output to bzip2 for compression and put it into
# the FIFO to be read by a cat program.
######## BUT: will tail output the whole of
# $MAILFILE before that file is deleted at the end, even
# if it is blocked for a long time waiting for bzip2 to
# compress the stuff and waiting for another command to
# read the results from $FIFONAME?
tail --follow=name "$MAILFILE" | bzip2 -9 > "$FIFONAME" &
if fetchmail --silent ; then
sleep 10 # check: is this necessary?
rm "$MAILFILE" # this kills tail.
else
echo Fetchmail returned with non-zero exit status.
fi
wait # for your children
--end script--
This script is to be executed from my home box thus:
home$ ssh fastinet
The question:
Apart from the method I use here, is there a better way (see BUT in the
scripts comments above) of killing tail (it must be killed to send EOF
so bzip2 finishes its task) and making sure that happens only iff it has
passed all mails from this fetchmail run to bzip2?
I think of somthing along the lines of:
1.) add a tee command between tail and bzip2, passing everything to
/tmp/tail-output.
2.) after fetchmail exited: check size of $MAILFILE every second and
exit this stage when it has not changed for x seconds.
3.) while ! cmp --silent $MAILFILE /tmp/tail-output; do sleep 1; done
4. ) rm $MAILFILE /tmp/tail-output (kills tail.)
Is there a better way? I really'd love to see fetchmail writing the
mails in unix mailbox format onto STDOUT ...
Marc
--
Marc Mutz <[EMAIL PROTECTED]> http://marc.mutz.com/Encryption-HOWTO/
University of Bielefeld, Dep. of Mathematics / Dep. of Physics
PGP-keyID's: 0xd46ce9ab (RSA), 0x7ae55b9e (DSS/DH)
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs