문제

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"
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top