观看文件进行更改 [英] Watch a file for change

查看:75
本文介绍了观看文件进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想观看对文件xyz.txt的任何更改,并在发生更改时通过电子邮件将整个文件发送给我.是否有一个内衬(或几行外壳脚本)?

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?

更新:

# 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

现在,如果有人可以显示如何在shell脚本或1个命令中绑定这两行.

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

推荐答案

尝试一下:

find /etc/ -name my.cnf -mtime 0 -exec sh -c 'cat {} | mail -E -s "file changed" shantanu@company.com' \;

mail-E选项可防止其发送带有空主体的消息(如find不返回任何内容且cat不输出任何内容的情况.

The -E option to mail prevents it from sending messages with empty bodies (as would be the case if find returns nothing and cat outputs nothing.

这篇关于观看文件进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆