Skip to content

Instantly share code, notes, and snippets.

@alismx
Created April 8, 2023 20:14
Show Gist options
  • Save alismx/6bb524c02a636a478f49d7387f57869b to your computer and use it in GitHub Desktop.
Save alismx/6bb524c02a636a478f49d7387f57869b to your computer and use it in GitHub Desktop.
This creates a lock based on the existence of a file
#!/bin/bash
LOCK_FILE="/var/lock/s3cmd.lock"
# Check if another instance is already running
if [[ -e $LOCK_FILE ]]; then
echo "Another instance of the script is already running. Exiting..."
exit 1
else
touch $LOCK_FILE
fi
function cleanup {
# Remove lock file upon exit
rm $LOCK_FILE
}
trap cleanup EXIT INT TERM
# Your code goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment