inotifywaitとrsyncが一時ファイル名を印刷しています。

inotifywaitとrsyncが一時ファイル名を印刷しています。

ディレクトリに新しいファイルが作成されるたびに、リモートサーバーにPOST要求を送信するbashスクリプトを作成しています。 RSYNCを使用して、複数のディレクトリをホームディレクトリに同期します。その後、ホームディレクトリが監視され、inotifywait新しいファイルが検出されると、スクリプトの実行がトリガされます。

問題は、RSYNCがここで読み取ったファイルを生成する方法です。Rsync一時ファイル拡張子RSYNCはmktempそれを使用して同様のファイル名を生成しますが、.filesynced.x12fj1コピーが完了した後に名前を変更します。filesynced

したがって、私のinotifywaitbashスクリプトは、名前が変更されたファイル名ではなく、一時ファイルのファイル名を取得します。移動して名前を変更した後にファイル名を取得できるように、誰かが私に正しい方向を伝えることができるかどうか疑問に思います。

#!/bin/bash
inotifywait -m -q -e close_write /edi-files |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        # send contents of $file to api endpoint.
    done

予約されたもの:

*/1 * * * * rsync -avz --no-perms --no-o --no-g --remove-source-files /home/dir3/upload/ /home/dir2/upload/ /home/dir1/upload/ /edi-files/

現在の出力:

The file '.xxxxxxx1.ATM.8I2mrS' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx2.ATM.MnIMPP' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx3.txt.3FSceN' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'
The file '.xxxxxxx4.txt.GoIDCK' appeared in directory '/edi-files/' via 'CLOSE_WRITE,CLOSE'

ベストアンサー1

おすすめ記事