From 9e8b0dd0bc6752299dbe111f2a43a4a91286cda2 Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Fri, 18 May 2018 19:49:55 +0200 Subject: [PATCH] offlineimap_sync.sh: add script for cronjob --- offlineimap_sync.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 offlineimap_sync.sh diff --git a/offlineimap_sync.sh b/offlineimap_sync.sh new file mode 100755 index 0000000..05a1e78 --- /dev/null +++ b/offlineimap_sync.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# sync offlineimap if you have connection to the internet +# and you can ping your imap server successfully. +# shamelessly stolen from +# https://hobo.house/2015/09/09/take-control-of-your-email-with-mutt-offlineimap-notmuch/ + +imapserver=$(cat ~/.offlineimaprc | grep remotehost | awk '{print $3}') +imapactive=$(ps -ef | grep '[o]fflineimap' | wc -l) +netactive=$(ping -c3 $imapserver >/dev/null 2>&1 && echo up || echo down) +mailsync="/usr/bin/offlineimap" + +# kill offlineimap if active, sometimes it hangs +case $imapactive in +'1') + killall offlineimap && sleep 5 +;; +esac + +# Check that you can access the SMTP server +case $netactive in +'up') + $mailsync +;; +'down') + : +;; +esac