
#!/bin/bash
watchDir="$1"
watchDir2="$2"
date1=$(date '+%Y-%m-%d-%H:%M:%S')
inotifywait -m -r --exclude \.log "$watchDir" "$watchDir2" -e attrib,delete,delete_self,close,close_write,close_nowrite,create,open,modify,move,moved_to,moved_from |
while read -r file; do
name=$(stat -c '%U' $file 2>/dev/null)
date=$(stat -c %Y $file 2>/dev/null | awk '{print strftime("%d-%m-%Y %T", $1,$2)}')
fileName=${file/* CREATE /}
echo "[${date%.*}]" "File: '$fileName' User: '$name'" >> /var/log/inotify/inotify-$date1.log
done
답변1
많은 연구 끝에 나는 이러한 제한 사항이 유용하다는 것을 알았습니다. inotify를 사용하면 파일을 변경한 사용자를 찾을 수 있는 방법이 없습니다.
제한사항을 읽어보세요.http://manpages.ubuntu.com/manpages/bionic/man7/inotify.7.html
제한 사항 및 참고 사항
inotify API는 inotify 이벤트를 트리거한 사용자 또는 프로세스에 대한 정보를 제공하지 않습니다. 특히, inotify를 통해 이벤트를 모니터링하는 프로세스가 자신이 트리거하는 이벤트와 다른 프로세스에 의해 트리거되는 이벤트를 구별하는 쉬운 방법은 없습니다.