dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 240b7e75a33d5fad27d04c9419a50ef7835bc08e
parent 84e5953f3b439630143e86abe3a5a2b3688cf617
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date:   Wed, 24 Feb 2016 11:44:37 -0800

add script which monitors and kills long offlineimap processes

Diffstat:
Abin/mailcheck.sh | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/bin/mailcheck.sh b/bin/mailcheck.sh @@ -0,0 +1,30 @@ +#!/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 $!