User Tools

Site Tools


notes:avoid_duplicated_cron_jobs_with_flock

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
notes:avoid_duplicated_cron_jobs_with_flock [2017/11/04 11:31] – created adminnotes:avoid_duplicated_cron_jobs_with_flock [2017/11/04 11:31] admin
Line 7: Line 7:
 Let's say you want to run offlineimap every two hours. Instead of simply scheduling in crontab the program (as vmail user) with: Let's say you want to run offlineimap every two hours. Instead of simply scheduling in crontab the program (as vmail user) with:
  
-* */2 * * * vmail offlineimap+  * */2 * * * vmail offlineimap
  
 you can run offlineimap through flock and use /tmp/offlineimap.lck as lock file with: you can run offlineimap through flock and use /tmp/offlineimap.lck as lock file with:
  
-* */2 * * * vmail flock -xn /tmp/offlineimap.lck -c 'offlineimap'+  * */2 * * * vmail flock -xn /tmp/offlineimap.lck -c 'offlineimap'
  
 This way, every two hours cron starts offlineimap: if the lock file is still around, it means that offlineimap is still synchronizing and the current execution is safely skipped. This way, every two hours cron starts offlineimap: if the lock file is still around, it means that offlineimap is still synchronizing and the current execution is safely skipped.
notes/avoid_duplicated_cron_jobs_with_flock.txt · Last modified: 2017/11/04 11:35 by admin