나는이 bash는 스크립트가 :inotifywait 용 Bash 스크립트 - 로그 파일에 삭제를 쓰는 방법과 cp close_writes?
이제#!/bin/bash
inotifywait -m -e close_write --exclude '\*.sw??$' . |
#adding --format %f does not work for some reason
while read dir ev file; do
cp ./"$file" zinot/"$file"
done
~
, 나는 그것이 같은 일을 할뿐만 아니라 로그 파일에 파일 이름을 작성하여 삭제 처리가 얼마나? 좋아해요?
#!/bin/bash
inotifywait -m -e close_write --exclude '\*.sw??$' . |
#adding --format %f does not work for some reason
while read dir ev file; do
# if DELETE, append $file to /inotify.log
# else
cp ./"$file" zinot/"$file"
done
~
편집 : 생성 된 메시지를보고
, 나는 파일이 닫힐 때마다 inotifywait를가 CLOSE_WRITE,CLOSE
를 생성하는 것을 발견했다. 그래서 제가 지금 제 코드를 점검하고 있습니다. DELETE
도 확인해 보았습니다. 그러나 어떤 이유로 코드 섹션이 작동하지 않습니다. 그것을 체크 아웃 :
#!/bin/bash
fromdir=/path/to/directory/
inotifywait -m -e close_write,delete --exclude '\*.sw??$' "$fromdir" |
while read dir ev file; do
if [ "$ev" == 'CLOSE_WRITE,CLOSE' ]
then
# copy entire file to /root/zinot/ - WORKS!
cp "$fromdir""$file" /root/zinot/"$file"
elif [ "$ev" == 'DELETE' ]
then
# trying this without echo does not work, but with echo it does!
echo "$file" >> /root/zinot.txt
else
# never saw this error message pop up, which makes sense.
echo Could not perform action on "$ev"
fi
done
를 디렉터리에서 나는 touch zzzhey.txt
을한다. 파일이 복사됩니다. 나는 vim zzzhey.txt
을하고 파일 변경 사항이 복사됩니다. rm zzzhey.txt
을 수행하고 파일 이름이 내 로그 파일 zinot.txt
에 추가됩니다. 굉장해!
어떻게 실행하나요? 이 스크립트 프로세스를 백그라운드로 보냅니 까? – Codex73
@ Codex73 다른 스크립트를 실행하는 것처럼 실행하고 다른 스크립트와 같이 백그라운드에서 실행하려면 백그라운드로 보냅니다. –
나는 많이 고마워했다. – Codex73