I am using bash and flock on centos.
Normally I would run cd /to/my/dir && python3.6 runcommand.py
But then we add it to cron and don't want output so add > /dev/null 2>&1
And add a flock before it to prevent multiple instances, like so:
flock -n ~/.my.lock cd /to/my/dir && python3.6 runcommand.py > /dev/null 2>&1
Question
Only does this flock the cd /to/my/dir
and then execute the python3.6
(normally without flock) or does it flock the complete row of bash commands (so both) and only unlock when python3.6 runcommand.py
is also finished?
Not clear from the man and examples I found.
Proverbs 27:23-27 -- Know well the condition of your flocks, and give attention to your herds, for riches do not last forever; and does a crown endure to all generations?
: a group of animals (such as birds or sheep) assembled or herded together. : a group under the guidance of a leader. especially : a church congregation.
Flock can be applied to glass, metal, plastic, paper or textiles. Flock design applications are also found on many items such as garments, greeting cards, trophies, promotional items, toys and book covers.
A flock of birds, sheep, or goats is a group of them. They are gregarious birds and feed in flocks. You can refer to a group of people or things as a flock of them to emphasize that there are a lot of them.
Shell interprets your command this way:
flock -n ~/.my.lock cd /to/my/dir && python3.6 runcommand.py > /dev/null 2>&1
flock -n ~/.my.lock cd /to/my/dir
partpython3.6 runcommand.py > /dev/null 2>&1
partSo, flock
has no business with &&
or the right side of it.
You could do this instead:
touch ./.my.lock # no need for this step if the file is already there and there is a potential that some other process could lock it
(
flock -e 10
cd /to/my/dir && python3.6 runcommand.py > /dev/null 2>&1
) 10< ./.my.lock
See this post on Unix & Linux site:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With