How do I make sure my bash script isn't already running?

后端 未结 13 914
無奈伤痛
無奈伤痛 2020-12-31 05:56

I have a bash script I want to run every 5 minutes from cron... but there\'s a chance the previous run of the script isn\'t done yet... in this case, i want the new run to j

13条回答
  •  粉色の甜心
    2020-12-31 06:23

    You can always just:

     if ps -e -o cmd | grep scriptname > /dev/null; then 
         exit
     fi
    

    But I like the lockfile myself, so I wouldn't do this without the lock file as well.

提交回复
热议问题