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.
You could use inotifywait
. It waits for changes to a file, and then executes a command (e.g. something like msmtp
in your case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With