在找到的文件上执行命令
问题描述:
我无法在找到的文件上使用exec和mail命令。在找到的文件上执行命令
# find /etc/ -name my.cnf -mtime 0 -exec mail [email protected]
find: missing argument to `-exec'
检查my.cnf中已经在过去24小时内
如果是被改变,因为在这种情况下,通过电子邮件
发送的文件,如果它尚未在上次更改24小时,什么也不做。
更新:
下面的脚本是工作正常,但我会喜欢这一切作为一个命令行的
#!/bin/sh
myfile=`find /etc/ -name my.cnf -mtime 0`
cat $myfile | mail -s "test" [email protected]
答
看来,你所需要的\旁;因此:
# find /etc/ -name my.cnf -mtime 0 -exec mail [email protected] \;
或怎么样:
# find /etc/ -name my.cnf -mtime 0 | xargs mail [email protected]
见http://www.softpanorama.org/Tools/Find/using_exec_option_and_xargs_in_find.shtml了有关使用发现
xargs的执行命令不返回任何东西。 -exec将发送邮件但没有消息。发送了一封空白邮件。 – shantanuo 2010-11-19 12:08:25