Skip to content

Instantly share code, notes, and snippets.

@steveluscher
Created May 10, 2016 05:43
Show Gist options
  • Save steveluscher/3916c4f2530a4de8ed391bf967839b2b to your computer and use it in GitHub Desktop.
Save steveluscher/3916c4f2530a4de8ed391bf967839b2b to your computer and use it in GitHub Desktop.
Learn spam in serial
#!/bin/bash
# Exit if *any* error is encountered
set -e
lockfile="/tmp/.sa-learn-lock"
# Make sure the lockfile exists
touch $lockfile
(
# Get the name of the lockfile's descriptor
unset descriptior
exec {descriptor}< $lockfile
# Block until you get an exclusive lock on that descriptor
flock -e $descriptor
cat | sa-learn "$@" &
exit 0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment