フォルダをスキャンしてDockerファイルを移動し、実行するbashスクリプト

フォルダをスキャンしてDockerファイルを移動し、実行するbashスクリプト

私はここに来たばかりで、現在小さなプロジェクトに取り組んでいます。

ファイルがドロップされるたびにフォルダーをスキャンするスクリプトを bash で記述する必要があります。2 番目の部分では、このファイルで使用されている名前で作成された新しいディレクトリにファイルを移動する必要があります。

使おうと思ったインクロンまたは時計しかし、それが良い解決策かどうかはわかりません。スキームは次のようになります。

directory="/usr/share/docker-compose"
if "*.yml" exist; then
   do 
      move /usr/share/used-images

前もって感謝します。

答え1

inotifywait を使うこともできます。サンプルスクリプト:

#!/bin/bash

watchdir="$1"

if ! [ -d "$watchdir" ]; then
    echo "Dir $watchdir doesn't exist"
    exit 1
fi

while file=$(inotifywait --format "%f" -e 'create' -e 'moved_to' "$watchdir"); do
    if [ -f "$watchdir/$file" ]; then
        tmpname=$(tempfile -d "$watchdir")
        mv "$watchdir/$file" "$tmpname"
        mkdir "$watchdir/$file"
        mv "$tmpname" "$watchdir/$file/$file"
        # YOURCOMMANDS
    fi
done

関連情報