2016-12-08 6 views
0

CentOS 7でinotify-toolsinotifywait)を使用して、すべてのファイル作成時にPHPスクリプトを実行しています。inotifyスクリプトが2回実行されますか?

私は次のスクリプトを実行すると:

# ps -x | grep mybash.sh 
    27723 pts/4 S+  0:00 /bin/sh /path/to/mybash.sh 
    27725 pts/4 S+  0:00 /bin/sh /path/to/mybash.sh 
    28031 pts/3 S+  0:00 grep --color=auto mybash.sh 

なぜつまり、どのように私はそれを修正することができます?

#!/bin/sh 
MONITORDIR="/path/to/some/dir" 
inotifywait -m -r -e create --format '%w%f' "${MONITORDIR}" | while read NEWFILE 
do 
    php /path/to/myscript.php ${NEWFILE} 
done 

を、私は2つのプロセスがある見ることができますか

+0

- すべて大文字の変数名前は、シェルやオペレーティングシステムにとって意味のある変数に使用されるPOSIXによって指定されますが、少なくとも1つの小文字の名前はアプリケーション用に予約されています。 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.htmlを参照してください。 –

答えて

0

パイプラインは複数のプロセスに分割されます。したがって、親スクリプトと、while readループを実行する別のサブシェルがあります。あなたはそれをしたくない場合は

、bashや代わりのkshで使用可能なプロセスの代替構文を使用します(以下シェバングはもはや#!/bin/shであることに注意していない):余談として

#!/bin/bash 
monitordir=/path/to/some/dir 

while read -r newfile; do 
    php /path/to/myscript.php "$newfile" 
done < <(inotifywait -m -r -e create --format '%w%f' "$monitordir") 
関連する問題