#!/bin/bash # set -o xtrace # return null string when filename expansion fails shopt -s nullglob declare cdir=$HOME/.offlineimap opts=("$@") declare logfile=$cdir/log lockfile=($cdir/*lock) timestamp=$(date "+%F %T %Z") exec 2>&1 exec >> $logfile # clean-up past runs [[ -e $lockfile ]] && rm $lockfile && \ echo "$timestamp: Cleaning up lock file $lockfile" # sync with Gmail if imap server is reachable nc -z imap.gmail.com 993 &> /dev/null && { echo "$timestamp: Syncing with Gmail"; offlineimap "${opts[@]}"; }