2 # Depends: lockfile-progs, ssh
6 echo "Usage: $0 hostname" 2>&1
10 DIR="$HOME/tmp/.bsmtp"
16 # TODO: Note that this scheme may currently lose mail if the local disk
17 # fills up! This is obviously very bad. Fix this.
19 # By default, lockfile-create gives up after three minutes, so don't cron
20 # this any more frequently than that without supplying a --retry argument.
21 lockfile-create "$HOST"
22 # Race condition pointed out by pjb: this doesn't guarantee that the lock is
23 # held before the critical section starts.
24 lockfile-touch "$HOST" &
26 trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM
29 ssh -2 -i "$HOME/.ssh/id-bsmtp-$HOST" -C "$HOST" bsmtp-pull-server > "$HOST"
30 [ -s "$HOST" ] || exit 0
31 /usr/sbin/sendmail -bS -odq < "$HOST"