I would recommend using run-one command - much simpler than dealing with the locks. From the docs:
run-one is a wrapper script that runs no more than one unique instance of some command with a unique set of arguments. This is often useful with cronjobs, when you want no more than one copy running at a time.
run-this-one is exactly like run-one, except that it will use pgrep and kill to find and kill any running processes owned by the user
and matching the target commands and arguments. Note that run-this-one will block while trying to kill matching processes, until all matching
processes are dead.
run-one-constantly operates exactly like run-one except that it
respawns "COMMAND [ARGS]" any time COMMAND exits (zero or non-zero).
keep-one-running is an alias for run-one-constantly.
run-one-until-success operates exactly like run-one-constantly except
that it respawns "COMMAND [ARGS]" until COMMAND exits successfully (ie,
exits zero).
run-one-until-failure operates exactly like run-one-constantly except
that it respawns "COMMAND [ARGS]" until COMMAND exits with failure (ie,
exits non-zero).
flock -n file commandandflock -n file -c command? – Nanne Feb 05 '15 at 14:40-cruns the specified command through a shell (as per the manpage), while the "bare" (non--c) form justexecs the command given. Putting something through the shell allows you to do shell-like things (such as running multiple commands separated with;or&&), but also opens you up to shell expansion attacks if you're using untrusted input. – womble Feb 06 '15 at 01:13frequent_cron_jobcommand that tried to show it was being run every minute. I've removed it since it added nothing useful, and caused confusion (yours, if nobody else's over the years). – womble Oct 31 '17 at 08:54flockdoes automatically. Ah well, learned a thing or two. ;) For anybody interested, here's the article I went through and it does a good job teaching you basic fundamentals of whatflock, no doubt, is doing (but likely better): https://bencane.com/2015/09/22/preventing-duplicate-cron-job-executions/ – Joshua Pinter Nov 17 '20 at 19:23