inotifywait를 사용하여 특정 확장자를 가진 파일 제외

inotifywait를 사용하여 특정 확장자를 가진 파일 제외

들어오는 암호화된 파일을 보고 있는데 확장자가 두 개 있습니다 testfile<date>.dat.pgp. 예를 들어 .

문제는 파일이 해독되면 testfile<date>.dat모니터 디렉터리에 새 file()이 생성되어 모니터 프로세스의 또 다른 원치 않는 실행이 트리거된다는 것입니다.

testfile<date>.dat제외 하고 포함하는 방법은 무엇 입니까 testfile<date>.dat.pgp?

이것은 내 코드입니다.

inotifywait -m -e create --format '%w%f'  "${MONITORDIR}"  |  while read  NEWFILE
do

    #decrypts testfile.dat.pgp
    # new file "testfile<date>.dat" is created in the $MONITOR_DIR which triggers
    # the inotifywait process to run again.

done

답변1

다음으로 전화를 착신전환하세요.grep

inotifywait -m -e create --format '%w%f' "${MONITORDIR}" |\
grep '.dat.pgp$' --line-buffered | while read  NEWFILE 
   do

   #decrypts testfile.dat.pgp
   # new file "testfile.dat" is created in the $MONITOR_DIR which triggers
   # the inotifywait process to run again.

   done

inotifywait가 있는 확장 프로그램만 시청 합니다 .dat.pgp.

답변2

while read 루프 내에서 파일을 건너뛸 수도 있습니다.

    inotifywait -m -e create --format '%w%f' "${MONITORDIR}" |\
    while read  -r NEWFILE; do 
       if [[ $NEWFILE == *.dat.pgp ]]; then
        #decrypts testfile.dat.pgp
        # new file "testfile.dat" is created in the $MONITOR_DIR which triggers
        # the inotifywait process to run again.
       fi
    done

해당 코드를 테스트하지는 않았지만 테스트에서는 다음 코드만 처리해야 합니다.*.dat.gpg

관련 정보