From ffe45b45b90af7664c1219e46db2cd42a2e505d3 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 26 Oct 2016 21:02:16 +0200 Subject: [PATCH] add a script to check if offlineimap is still working The script needs to run as a cronjob --- desktop/offlineimap/offlineimap.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 desktop/offlineimap/offlineimap.sh diff --git a/desktop/offlineimap/offlineimap.sh b/desktop/offlineimap/offlineimap.sh new file mode 100755 index 0000000..a76b9a2 --- /dev/null +++ b/desktop/offlineimap/offlineimap.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Check every ten seconds if the process identified as $1 is still +# running. After 5 checks (~60 seconds), kill it. Return non-zero to +# indicate something was killed. +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 -u quiet & monitor $!