Results 1 to 8 of 8
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.
Code:
#!/bin/sh
/usr/bin/fetchmail -v ...
- 11-07-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 13
How to disconnect modem when postfix queue empty??
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.
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.Code:#!/bin/sh /usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log killall wvdial
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.
- 11-08-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I've not mucked with postfix in forever, but basically you need to figure out how to query the status of the queue (maybe by looking in /var/spool/clientmqueue or by running 'postqueue -p' and evaluating the output).
Assuming 'postqueue -p' reports "0 Requests" if empty (I have no idea, just made that up), then you could do something like:
It may be that you want to run the queue checking code in a loop and run fetchmail until it is empty - up to you. If you do, just insert this:Code:#!/bin/sh /usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log # run some command to look for more jobs in queue (this is made up!) postqueue -p|grep 0\ Requests # if the above command returns 'true' (queue is empty) if [ $? -eq 0 ]; then killall wvdial exit 0 # if the above command returned 'false' (queue is not empty) else echo Queue is not empty - not killing wvdial fi
Again, this is just skeleton framework - you need to figure out how to check on the queue. Maybe something in that fetchmail.log has something?Code:while; do (above code) sleep 1 done
- 11-09-2011 #3Just Joined!
- Join Date
- Mar 2011
- Posts
- 13
Ok! following you skeleton framework i get it to work perfectly in this way.
but when i add the while for run the queue checking code in a loop in the way that you mention it gives me unespected syntax error (my system is in spanish)Code:#!/bin/sh postqueue -p|grep empty if [ $? -eq 0 ]; then killall wvdial fi
línea 2: error sintáctico cerca del elemento inesperado `;'
línea 2: `while; do'
here is the code:
Code:#!/bin/sh while; do #the error is on this line, is here something missed? postqueue -p|grep empty if [ $? -eq 0 ]; then killall wvdial fi sleep 1 done
- 11-09-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
not this
but thisCode:while; do
and i reiterate - that postqueue command is surely not what you want. you'll need to figure it out.Code:while :; do
EDIT: did not see the top of your post about postqueue - so that works, eh? great!
EDIT2: Krikey! just realized you were using MY original typo - sorry!Last edited by atreyu; 11-09-2011 at 06:23 PM. Reason: oops!
- 11-09-2011 #5Just Joined!
- Join Date
- Mar 2011
- Posts
- 13
Sure! the postqueue command perfectly works, i just haved to change 0\ Requests by empty cause it is part of the text that gives me the shell when is fully empty.
if the queue is empty and i type postqueue -p it returns to me "Mail queue is empty"
so if i place postqueue -p|grep empty the value of $? is going to be 0
and if the queue is not empty the value of $? is 1
after testing and knowing that i can perfectly go to compare if [ $? -eq 0 ] to then do the killall wvdial
now i am going to fix the script adding the while how you tell me to make it loop. then i will post the results
- 11-09-2011 #6Just Joined!
- Join Date
- Mar 2011
- Posts
- 13
I got it!
i finally solve it! this is the final solution, it works like a charm!
so now my final script under /etc/ppp/ip-up.d is like this:Code:while ! postqueue -p | grep -q empty; do sleep 1 done killall wvdial
fetchmail could finish his job but the modem wont disconect until also the mail queue is empty!Code:#!/bin/sh /usr/sbin/postqueue -c /etc/postfix -f /usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log while ! postqueue -p | grep -q empty; do sleep 1 done killall wvdial
thanks a lot by your help @atreyu, in fact is atreyu by the hardcore band? if is it i where a big fan of them in their times!
- 11-09-2011 #7Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
ˇNo problemo!thanks a lot by your help @atreyu, in fact is atreyu by the hardcore band? if is it i where a big fan of them in their times!
~atreyu
- 11-09-2011 #8Just Joined!
- Join Date
- Mar 2011
- Posts
- 13
Ohhh by the film... jajaj great film also


Reply With Quote