Crontab, prevent duplicate process

Sometimes you want to use crontab to run some scripts from time to time, but you are not sure how much it will take. And you want to avoid run more than one process of the script at the same time.

This will do the trick:

*/MINUTES    *       *       *       *       if [ `ps aux | grep NAME | grep -v “grep” | wc -l` -eq 0 ]; then  /…/NAME  ; fi

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>