From b4f1bdc9d88dd7c091116d70948668f1499efbee Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 19 Jun 2016 22:36:00 +1200 Subject: Add getmails --- README.markdown | 3 +++ bin/getmails | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 bin/getmails diff --git a/README.markdown b/README.markdown index 7511ecee..4e1d0851 100644 --- a/README.markdown +++ b/README.markdown @@ -292,6 +292,9 @@ Scripts prints the hostname if the command returns zero. * `edda(1)` provides a means to run `ed(1)` over a set of files preserving any options, mostly useful for scripts. +* `getmails` runs a set of `getmailrc` files; does much the same + thing as the script of the same name in the `getmail` suite, but runs the + requests in parallel and does up to three silent retries using `try(1)` * `han(1)` provides a `keywordprg` for Vim's Bash script filetype that will look for `help` topics. You could use it from the shell too. * `igex(1)` wraps around a command to allow you to ignore error conditions diff --git a/bin/getmails b/bin/getmails new file mode 100755 index 00000000..d8383564 --- /dev/null +++ b/bin/getmails @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# +# Run getmail(1) over every getmailrc.* file in ~/.getmail (I didn't like the +# included getmails(1) script). +# +# Author: Tom Ryder +# Copyright: 2016 +# +self=getmails + +# Check for existence of needed commands +hash flock getmail try || exit + +# Create a directory for our lockfiles if need be; we'll just leave it there +lockdir=${TMPDIR:-/tmp}/getmail-$UID +if ! mkdir -p -- "$lockdir" ; then + printf "%s: Could not create lockdir %s\n" \ + "$self" "$lockdir" >&2 + exit 1 +fi + +# Iterate through the getmailrc.* files in $GETMAIL if defined, or +# $HOME/.getmail if not +for rcfile in "${GETMAIL:-$HOME/.getmail}"/getmailrc.* ; do + + # Run the current rcfile with getmail quietly, using its basename with + # .lock appended as the lockfile in the lock directory + ( + flock -n 9 || exit 1 + try -i 15 -n 3 getmail --rcfile "$rcfile" "$@" + ) 9>"$lockdir"/"${rcfile##*/}".lock & +done + +# Wait for all of the enqueued tasks to finish +wait -- cgit v1.2.3