Reputation: 3433
I have the following cron job
7,22,37,52 6-16 * * * myuser /bin/bash -l -c "cd /to/my/path/; rake my_rake_task"
I need to use this with some file locking so the task doesn't run more than once, and looking about, I see flock is a good tool for this scenario.
My question is, what is the right syntax for using flock with the above? Here's what I'm guessing, but, I have the extra user definition and so forth.
Is this correct?
flock -n /var/run/my_app.lock -c 7,22,37,52 6-16 * * * myuser /bin/bash -l -c "cd /to/my/path/; execute_my_command"
Upvotes: 0
Views: 3721
Reputation: 5721
No, this is not correct. See man crontab
for syntax of the crontab files. The correct command would look like:
7,22,37,52 6-16 * * * myuser /bin/bash -l -c "cd /to/my/path/ && flock -n /var/run/my_app.lock -c execute_my_command"
..but a cleaner approach is to put it into a wrapper script and run that script from cron
.
Upvotes: 3