Alex Rivera | Logout

Watch a file for change

Asked 2010-11-19T10:37:04.607
11

I want to watch any changes to a file xyz.txt and email me the entire file whenever there is a change. Is there One Liner (or a few lines shell script) for this?

Update:

# Check if my.cnf has been changed in the last 24 hours
# if yes, as in the following case, simply send the file
# if it has not been changed in the last 24 hours, do nothing.

# find /etc/ -name my.cnf -mtime 0
/etc/my.cnf

# cat /etc/my.cnf | mail shantanu@company.com

Now if someone can show how to bind these two lines in a shell script or in 1 command.

Edit
Report

1 Answer

10

You should look into inotify which can watch a file or directory and report changes.

answered 2010-11-19T10:39:57.400

Your Answer