Skip to content

Instantly share code, notes, and snippets.

@drzippie
Created December 30, 2013 16:57
Show Gist options
  • Select an option

  • Save drzippie/8184696 to your computer and use it in GitHub Desktop.

Select an option

Save drzippie/8184696 to your computer and use it in GitHub Desktop.
Check shellscript - check is running
#!/bin/bash
#
lockdir=/tmp/diario_stocks.lock
if mkdir "$lockdir"
then
echo >&2 "successfully acquired lock"
# Remove lockdir when the script finishes, or when it receives a signal
trap 'rm -rf "$lockdir"' 0 # remove directory when script finishes
# Optionally create temporary files in this directory, because
# they will be removed automatically:
# tmpfile=$lockdir/filelist
else
echo >&2 "cannot acquire lock, giving up on $lockdir"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment