shell - Alert when file content changes -
this question has answer here:
- monitor directory content change 2 answers
i want write shell script checks logic files placed @ /var/www/html/
and, if user makes change in files, sends alert administrator informing them "user x has made change in f file." not have experience in writing shell scripts, , not know how start. highly appreciated.
this answered in superuser: https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes
basically use inotifywait
simple, using inotifywait:
while inotifywait -e close_write myfile.py; ./myfile.py; done
this has big limitation: if program replaces myfile.py different file, rather writing existing myfile, inotifywait die. editors work way.
to overcome limitation, use inotifywait on directory:
while true; change=$(inotifywait -e close_write,moved_to,create .) change=${change#./ * } if [ "$change" = "myfile.py" ]; ./myfile.py; fi done
the asker has put script online that, can called this:
while sleep_until_modified.sh derivation.tex ; latexmk -pdf derivation.tex ; done
Comments
Post a Comment