폴더를 스캔하여 도커 파일을 이동하고 실행하는 bash의 스크립트

폴더를 스캔하여 도커 파일을 이동하고 실행하는 bash의 스크립트

저는 여기에 새로 왔고 현재 작은 프로젝트를 진행하고 있습니다.

파일이 폴더에 포함될 때마다 폴더를 검색하려면 bash에 스크립트를 작성해야 합니다. 두 번째 부분에서는 이 파일에서 사용하는 이름으로 생성된 새 디렉터리로 파일을 이동해야 합니다.

사용하려고 생각했는데증분또는보다하지만 그것이 좋은 해결책인지는 모르겠습니다. 계획은 다음과 같습니다.

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

관련 정보