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

Both sides previous revisionPrevious revision
notes:avoid_duplicated_cron_jobs_with_flock [2017/11/04 11:31] adminnotes:avoid_duplicated_cron_jobs_with_flock [2017/11/04 11:35] (current) admin
Line 6: Line 6:
  
 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.1509795113.txt.gz · Last modified: 2017/11/04 11:31 by admin