观看文件进行更改

编程入门 行业动态 更新时间:2024-10-27 06:21:56
本文介绍了观看文件进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想观看对文件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.

更多推荐

观看文件进行更改

本文发布于:2023-11-06 17:35:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!