X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/4187e68ee41a4254a84cd0f2fbd4e8b4ab8ce5c5..615048bfd1613d6277505cf205e726fdee6677f6:/bin/offlineimap.cron diff --git a/bin/offlineimap.cron b/bin/offlineimap.cron new file mode 100755 index 0000000..3c26e5f --- /dev/null +++ b/bin/offlineimap.cron @@ -0,0 +1,27 @@ +#!/bin/bash +# http://pbrisbin.com/posts/mutt_gmail_offlineimap/ + +monitor() { + local pid=$1 i=0 + + while ps $pid &>/dev/null; do + if (( i++ > 5)); then + echo "Max checks reached. Sending SIGKILL to ${pid}..." >&2 + kill -9 $pid; return 1 + fi + + sleep 10 + done + + return 0 +} + +read -r pid < ~/.offlineimap/pid + +if ps $pid &>/dev/null; then + echo "Process $pid already running. Exiting..." >&2 + exit 1 +fi + +offlineimap -o & monitor $! +