On 09-Jan-99 Mario Melendez Esquivel wrote:
> Every morning, I perform the same routine: open up my dialup connection,
> send unsent messages, get messages from my ISP and disconnect. I would like
> to automate this procedure in a script.
>
> The problem is this: I write it up in a script like so:
>
> pon MyISP
> sendmail -q
> fetchmail
> poff
>
> But since Linux executes in background, what happens is that pon is left to
> dial in the background, sendmail is executed, and since no dialup connection
> exists (yet) sendmail fails, fetchmail fails, and poff kills the dialup in
> progress.
>
> How can I halt the script until the connection is up and running, and better
> yet: how do I keep it from executing poff until fetchmail is done?
Here's a possible solution:
pon MyISP
while ! ifconfig ppp0 | grep RUNNING > /dev/null; do
sleep 1
done
sendmail -q
fetchmail
wait $!
poff
The while loop will keep on executing "sleep 1" as long as the ppp connection
is not up. In the "wait" instruction, "$!" will be expanded into the process ID
of the previous process, in this case, "fetchmail". The "wait" instruction will
then wait for the specified process to terminate before it terminates itself
and allow the next instruction to be executed.
Cort
[EMAIL PROTECTED]