- if nice -n 19 offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
- perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
+ # source the ssh info if it exists
+ if [ -e ~/.ssh/"ssh_agent_info_$HOSTNAME" ]; then
+ . ~/.ssh/"ssh_agent_info_$HOSTNAME" > /dev/null;
+ fi;
+ PID="$(pgrep -U $(id -u) offlineimap)";
+ if [ -n "$PID" ]; then
+ # if offlineimap has been running for more than 20 minutes
+ if [ $(( $(date +'%s') - $(stat -c '%Y' /proc/$PID/cmdline) )) -gt 1200 ]; then
+ kill "$PID" >/dev/null 2>&1 || true;
+ sleep 5
+ kill -0 "$PID" >/dev/null 2>&1 && kill -9 "$PID" >/dev/null 2>&1;
+ PID="$(pgrep -U $(id -u) offlineimap)";
+ fi;
+ fi;
+ if [ -z "$PID" ]; then
+ if nice -n 19 ${IONICE} offlineimap -o -u Noninteractive.Basic 2>&1 |grep validity| \
+ perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;