Skip to content

Instantly share code, notes, and snippets.

@agazso
Created March 3, 2013 21:01
Show Gist options
  • Select an option

  • Save agazso/5078270 to your computer and use it in GitHub Desktop.

Select an option

Save agazso/5078270 to your computer and use it in GitHub Desktop.
Run commands protected by lock
#!/bin/sh
LOCKFILE=/tmp/meeting_dashboard.lock
COMMAND="$*"
[ "$1" = "" ] && (echo usage $0 command; exit 1)
# Previous run should execute successfully:
[ -f $LOCKFILE ] && exit 0
# Upon exit, remove lockfile.
cleanup()
{
rm -f $LOCKFILE
exit $?
}
trap cleanup EXIT SIGINT
touch $LOCKFILE
$COMMAND
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment