Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch a file for change

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 [email protected]

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

like image 351
shantanuo Avatar asked Nov 19 '10 10:11

shantanuo


1 Answers

You could use inotifywait. It waits for changes to a file, and then executes a command (e.g. something like msmtp in your case).

like image 194
igor Avatar answered Sep 19 '22 12:09

igor