Skip to content

Instantly share code, notes, and snippets.

@randallknutson
Created February 13, 2014 16:27
Show Gist options
  • Save randallknutson/8978455 to your computer and use it in GitHub Desktop.
Save randallknutson/8978455 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Makes sure we exit if flock fails.
set -e
(
# Wait for lock on /var/lock/.lockfile.lock (fd 200) for 10 seconds
flock -x -w 10 200
timeout 2h /command/to/run > /var/log/logfile 2>&1
) 200>/var/lock/.lockfile.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment