本文介绍了观看文件进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想观看对文件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 myf 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 myf -mtime 0 /etc/myf # cat /etc/myf | mail shantanu@company现在,如果有人可以显示如何在shell脚本或1个命令中绑定这两行.
Now if someone can show how to bind these two lines in a shell script or in 1 command.
推荐答案尝试一下:
find /etc/ -name myf -mtime 0 -exec sh -c 'cat {} | mail -E -s "file changed" shantanu@company' \;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.
更多推荐
观看文件进行更改
发布评论