LoginSignup
27
27

More than 5 years have passed since last update.

shell スクリプト二重起動防止

Last updated at Posted at 2015-06-30

特に説明する部分でもないですが、cron等の繰り返し設定で2重に起動しないようにするbashです。該当シェルスクリプトの先頭に追加しておくと便利

# 二重起動防止
_process=`basename $0`

_pcnt=`pgrep -fo ${_process} | wc -l`

if [ ${_pcnt} -gt 1 ]; then
  echo "This script has been running now. proc : ${_pcnt}"
  exit 1
fi
27
27
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
27