Created
April 8, 2023 20:14
-
-
Save alismx/6bb524c02a636a478f49d7387f57869b to your computer and use it in GitHub Desktop.
This creates a lock based on the existence of a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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