Created
May 24, 2012 08:24
-
-
Save keiya/2780201 to your computer and use it in GitHub Desktop.
シェルスクリプト排他処理のサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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