sha*_*nuo 7 linux shell command-line
我想观察文件xyz.txt的任何更改,并在发生更改时通过电子邮件发送给我整个文件.是否有一个Liner(或几行shell脚本)?
更新:
# 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
Run Code Online (Sandbox Code Playgroud)
现在,如果有人可以展示如何在shell脚本或1命令中绑定这两行.
尝试一下:
find /etc/ -name my.cnf -mtime 0 -exec sh -c 'cat {} | mail -E -s "file changed" shantanu@company.com' \;
Run Code Online (Sandbox Code Playgroud)
-E阻止mail它发送带有空正文的消息的选项(如果不返回任何内容并且不输出任何内容,就会出现这种情况find)cat。