Skip to content

Instantly share code, notes, and snippets.

@mturquette
Created January 18, 2016 07:46
Show Gist options
  • Save mturquette/0237243502b3fe5d142f to your computer and use it in GitHub Desktop.
Save mturquette/0237243502b3fe5d142f to your computer and use it in GitHub Desktop.
*/15 * * * * ~/.local/bin/mail.cron
#!/bin/bash
PID=$(pgrep offlineimap)
LOCK=/var/lock/mail
# offlineimap freezes up a lot. kill if previous job is still running
[[ -n "$PID" ]] && kill $PID
# sub-shell below is locked to prevent concurrency
(
# bail early if lock is held
flock -n 9 || exit 1
/usr/bin/offlineimap -o -a baylibre -u basic | /usr/bin/logger
) 9>$LOCK
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment