Skip to content

Instantly share code, notes, and snippets.

@keiya
Created May 24, 2012 08:24
Show Gist options
  • Select an option

  • Save keiya/2780201 to your computer and use it in GitHub Desktop.

Select an option

Save keiya/2780201 to your computer and use it in GitHub Desktop.
シェルスクリプト排他処理のサンプル
#!/bin/sh
cd /var/www/html/application/batch_scripts
LOGDIR=batch_logs
LOCKFILE=$LOGDIR/lock
trap "echo Trapped; rm -f $LOCKFILE; exit" INT QUIT TERM
# ロックファイルがあれば60秒*最大3回待機、1日前のロックファイルなら無視
if lockfile -60 -r 3 -l 86400 $LOCKFILE
then
# 本決済バッチ
php honkessai.php 1> $LOGDIR/honkessai.log 2> $LOGDIR/honkessai_error.log
# メール系バッチを3つ同時に並列実行
php mail-oneday-before.php 1> $LOGDIR/mail-oneday-before.log 2> $LOGDIR/mail-oneday-before_error.log |
php mail-3days-before.php 1> $LOGDIR/mail-3days-before.php 2> $LOGDIR/mail-3days-before_error.php |
php today.php 1> $LOGDIR/today.log 2> $LOGDIR/today-error.log
# 画像生成
php image-publish.php 1> $LOGDIR/image_publisher.log 2> $LOGDIR/image_publisher_error.log
rm -f $LOCKFILE
else
echo "The process is already running."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment