Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  44] [ 0]  / answers: 1 / hits: 32158  / 3 Years ago, tue, may 4, 2021, 10:01:04

I am looking for a simple and generic solution that would allow you to execute any script or application in crontab and prevent it from running twice.



The solution should be independent on the executed command.



I assume it should look like lock && (command ; unlock) where lock will return false if there was another lock.



The second part would be like if it acquired the lock, run command and unlock after command is executed, even if it returns error.


More From » bash

 Answers
0

Take a look at the run-one package. From the manpage for the run-one command Manpage icon:



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.



Like time or sudo, you just prepend it to the command. So a cronjob could look like:


  */60 * * * *   run-one rsync -azP $HOME example.com:/srv/backup

For more information and background, check out the blog post introducing it by Dustin Kirkland.


[#38122] Thursday, May 6, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
entmpy

Total Points: 52
Total Questions: 112
Total Answers: 113

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
entmpy questions
;