Software Engineering Note

cron job 한번만 실행되도록 하기 본문

삽질과 꿀팁사이

cron job 한번만 실행되도록 하기

devmoons 2017. 1. 19. 19:34

간단한 방법이 없나 찾아봤더니 이런게 있었다.


http://serverfault.com/questions/82857/prevent-duplicate-cron-jobs-running/82863#82863


난 처음보는거라...ㅋ


"/usr/bin/flock -n /tmp/my.lockfile /bin/sh test.sh" 


이런식으로 실행해보면 test.sh이 실행중인 경우, test.sh은 중복 실행이 안된다.


man page


      -n, --nb, --nonblock

              Fail (with an exit code of 1) rather than wait if the lock cannot be immediately acquired.