Example with the command-line tool flock.
The documentation just defines the syntax:
flock [options] <file> -c <command>
But -c seems not to be mandatory.
This line executes a program if locking of a file is possible (the '-n' switch disable wait for lockfile release):
flock -n lockfile.lck echo "File is Locked"
I would like, instead, to make a script like:
flock -n $TMP/lockfile.lck (
echo "Congratulations:"
echo "you have acquired the lock of the file"
)
As you can see, it is nearly the same, but executing more than one line.
Is it possible?
And, for the case when locking is not possible:
flock -n lockfile.lck echo "Lock acquired" || echo "Could not acquire lock"
I would like to know if it can be implemented something like :
flock -n $TMP/lockfile.lck (
echo "Congratulations:"
echo "you have acquired the lock of the file"
) || (
echo "How sad:"
echo "the file was locked."
)
Thanks.