I have a file called alarm.log, and I want a script to automatically run when this file is changed.
2 Answers
You should check out inotify, specifically inotyfywait (man page here).
Basic usage:
while inotifywait -e modify alarm.log; do <myScript>; done
There are plenty of good examples of usage in this thread.
- 
        I have a file script who ping host and when to someone host has packet lost write in log file.Nikolay Tehmendzhiev– Nikolay Tehmendzhiev2016-10-19 09:24:11 +00:00Commented Oct 19, 2016 at 9:24
 
If you are running systemd, check out systemd.path . Systemd path units use inotify internally, but by using a systemd unit you get a service that is running in the background independently of your login session.