This post shows how to lock a file using a shell script. This can be useful to avoid multiple executions of the same script.

This is the code:

#!/bin/bash
set -e
(
        /usr/bin/flock -n 200
        # do stuff
        
) 200>fileToLock

With set -e execution ends if flock commands fails to lock the file.

ciao