I am running array jobs on slurm, so every job needs to copy a file from a local directory to a temporary one. This cp
should not occur simultaneously.
This is the code I came up with:
mydirectory=mydb
LOCKFILE_1=${mydirectory}.lock
set -e
(
flock -w 3600 200 # Wait for the lockfile for max. 1 hour (3600 s), to not block the queue forever in case of dead lock files.
cp -r ${mydirectory} $TMPDIR/newdestinationdirectory
) 200>$LOCKFILE_1
set +e
Is this code doing the right thing? Or do I need
rm -f $LOCKFILE_1
for removing the lockfile again?