Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (34 sloc) 800 Bytes
#!/bin/bash
#[ -d .offlineimap/log ] || mkdir .offlineimap; touch .offlineimap/log
name=$(basename "$0")
lock=/tmp/${name}_${USER}.pid
if [ -f $lock ] && kill -0 $(cat $lock) &>/dev/null
then
exit 1
else
echo $$ > $lock
fi
trap '' SIGHUP
trap "{ rm -f $lock; exit 1; }" SIGINT SIGTERM EXIT
while true
do
# Is offlineimap ok?
sed '/^$/!h;$!d;g' ~/.offlineimap/log |grep -q -E "^-+$"
if [ "$?" != "0" ]
then
kill $(cat .offlineimap/pid) &>/dev/null
fi
# Is offlineimap dead?
kill -0 $(cat .offlineimap/pid) &>/dev/null
if [ "$?" != "0" ]
then
cat <<- EOF >> ~/.offlineimap/log
--------------------------------
offlineimap started: $(date +'%Y-%m-%d %H:%M')
--------------------------------
EOF
nohup offlineimap &>> ~/.offlineimap/log &
fi
sleep 120
done
exit 0