![inotifywait를 사용하여 특정 확장자를 가진 파일 제외](https://linux55.com/image/167065/inotifywait%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%ED%8A%B9%EC%A0%95%20%ED%99%95%EC%9E%A5%EC%9E%90%EB%A5%BC%20%EA%B0%80%EC%A7%84%20%ED%8C%8C%EC%9D%BC%20%EC%A0%9C%EC%99%B8.png)
들어오는 암호화된 파일을 보고 있는데 확장자가 두 개 있습니다 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