bashスキャンフォルダのスクリプトにdockerファイルを移動して実行します。

bashスキャンフォルダのスクリプトにdockerファイルを移動して実行します。

私はここに新しく来て、現在小さなプロジェクトを進めています。

ファイルを挿入するたびに、フォルダを検索するスクリプトを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

おすすめ記事