]> git.donarmstrong.com Git - bin.git/commitdiff
handle missing pid and sleep longer before killing
authorDon Armstrong <don@donarmstrong.com>
Wed, 18 Jan 2012 18:33:09 +0000 (18:33 +0000)
committerDon Armstrong <don@donarmstrong.com>
Wed, 18 Jan 2012 18:33:09 +0000 (18:33 +0000)
getmail

diff --git a/getmail b/getmail
index 539fbfe821e60bf7e6a34e4dc8a52a30ed8b2b0e..ac82e97e72d678bf3c295614cc088857b219fb65 100755 (executable)
--- a/getmail
+++ b/getmail
@@ -29,23 +29,26 @@ if [ -z "$CRON" ] || kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
            # if offlineimap has been running for more than 20 minutes
            if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then
                kill "$PID" >/dev/null 2>&1 || true;
-               sleep 1
+               sleep 5
                kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
+               PID="$(pgrep -U $(id -u) offlineimap)";
            fi;
        fi;
-       if nice -n 19 offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
-           perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
+       if [ -z "$PID" ]; then
+           if nice -n 19 offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
+               perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
                       next unless defined $account and length $account;
                       qx(/home/don/bin/deletemailbox -a $account $list > /dev/null);'; then
            # Clean the lists up too
-           for account in bugs lists; do
-               find /home/don/Mail/$account -maxdepth 1 -mindepth 1 -type d \
-                   -exec sh -c 'test $(find "{}" -type f |wc -l) -eq 0' ';' \
-                   -printf '%f\000'|xargs -0 -rn 1 ~/bin/deletemailbox -a $account >/dev/null 2>&1;
-               find /home/don/Mail/$account -maxdepth 2 -mindepth 2 -iname 'new' \
-                   -type d -ctime +60 -printf '%h\n'|xargs -rn 1 basename|xargs \
-                   -rn 1 /home/don/bin/deletemailbox -a $account >/dev/null 2>&1;
-           done;
+               for account in bugs lists; do
+                   find /home/don/Mail/$account -maxdepth 1 -mindepth 1 -type d \
+                       -exec sh -c 'test $(find "{}" -type f |wc -l) -eq 0' ';' \
+                       -printf '%f\000'|xargs -0 -rn 1 ~/bin/deletemailbox -a $account >/dev/null 2>&1;
+                   find /home/don/Mail/$account -maxdepth 2 -mindepth 2 -iname 'new' \
+                       -type d -ctime +60 -printf '%h\n'|xargs -rn 1 basename|xargs \
+                       -rn 1 /home/don/bin/deletemailbox -a $account >/dev/null 2>&1;
+               done;
+           fi;
        fi;
     fi;
 fi;