When you connect, you run fetchmail and kill, but you want only to kill if the queue is empty .. this will only be checked once .. if the queue at that point is not empty, the connection will stay open indefinitly, not what you want i think.
maybe you should fork another script after fetchmail. That script will keep checking the mailqueue and when it's empty, close ppp0
so:
Code:
#!/bin/bash
/usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log
/script/location/checkqueue.sh &
checkqueue.sh:
Code:
#!/bin/bash
while ( true )
do
SIZE=`find /var/spool/postfix/{deferred,active,maildrop}/ -type f | wc -l`;
if [ $SIZE -eq 0 ];
killall wvdial;
fi
sleep 10;
done
exit 0;
checkqueue.sh will check every 10 seconds if there are still mails in the queue left to be send, if none, execute killall, else wait 10seconds and check again.
I used find, since it's much faster then mailq when you have a lot of mail in the queue.