1

in /etc/ppp/ip-up.d/script I have the following that runs fetchmail when the ppp0 interface is up (connected) and when it finish the modem ends internet conection automatically.

 #!/bin/sh
 /usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log
 killall wvdial

this works perfectly. now i need to add to the script below the fetchmail command execution something that checks if the mail queue of postfix is completely empty and if is true then execute the command killall wvdial to hangup the modem.

In theory i know i could do something using if, else, do, while, until, etc. but in practice i do not know how to develop it. I would like you guys to help me to program and complete this script to work properly. I appreciate the comments.

nerdhacker
  • 61
  • 2
  • 5
  • Are you wanting to flush the postfix send queue (have it send all it's outgoing messages) and then hang up? If this is the case, you'll want to configure Postfix to send to a smarthost. If not, you'll come across situations where a message is refused by the destination host (e.g. 4xx temp error) and postfix will requeue the message for a time, during which the modem will stay active since the queue isn't empty. – NorbyTheGeek Nov 07 '11 at 16:47
  • No i just want to killall wvdial process when the postfix queue gets empty, postfix already start to flush the queue since it detect the ppp0 interface up. – nerdhacker Nov 07 '11 at 19:32

1 Answers1

3

I'm no expert in bash, but after some quick research I think this will do what you want:

while [ `find /var/spool/postfix/{deferred,active,maildrop}/ -type f | wc -l` -gt 0 ]; do
    sleep 5
done

This should loop every 5 seconds until the postfix queues are empty. Adjust your path to postfix files accordingly.

You might want to leave the deferred part out of the find command, otherwise any temp send errors that cause an email to be deferred will keep the modem connection open until it retries.

NorbyTheGeek
  • 415
  • 1
  • 6
  • 22