0

I have this script inside /etc/ppp/ip-up.d/script

#!/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

in this script it disconects my modem when detects that the mail queue is empty, also i wish to check if the fetchmail process is still running or execute the part of the while just and just after the fetchmail command finish to do his job completely.

some help please?

nerdhacker
  • 61
  • 2
  • 5

1 Answers1

1

Since you are not running fetchmail in daemon mode, the script will not start the while loop until fetchmail has exited.

I don't think you will save any time by starting your while loop before fetchmail finishes running.

Jeff Strunk
  • 2,127
  • 1
  • 24
  • 29
  • Yes thats the point y was thinking at, until fetchmail exit of work it will do the while check, but in the practice i dont know why but it is procesing the while check and if the queue gets empty it disconects my modem letting to fecthmail at the half way, thats why i would like to add a command to start the while loop before fetchmail or add that besides to check if the queue is empty check if the process of fecthmail is not running – nerdhacker Nov 10 '11 at 21:04
  • Can you please post a sanitized version of your fetchmailrc? – Jeff Strunk Nov 10 '11 at 21:10
  • defaults proto pop3 poll pop.gmail.com user "userxxx" pass "password" is userxxxx ssl – nerdhacker Nov 10 '11 at 21:36
  • I think something else must be ending your connection early. Put some debug echo statements in your script to tell you when things are happening. – Jeff Strunk Nov 10 '11 at 21:46
  • Hmm great idea, please how can i put this? i am not too experiencied in bash scripting – nerdhacker Nov 10 '11 at 21:49
  • just add the echo command with distinct output between each line: http://pastebin.com/Z7VQrDJY – Jeff Strunk Nov 10 '11 at 21:54
  • OK i have putted inside the echo output, now how can i see the output of the full script when it starts to excute? – nerdhacker Nov 10 '11 at 22:35
  • Try disabling it from running automatically, then you can run it in an interactive shell to see the output. Alternatively, there may be some output in a log in /var/log. – Jeff Strunk Nov 12 '11 at 14:53